1- using System . Text ;
1+ using System . Net ;
2+ using System . Text ;
23
34namespace SAPI . API . Utilities
45{
@@ -16,11 +17,11 @@ public static class Auth
1617/// </summary>
1718/// <param name="keys">List of all API keys authorized</param>
1819/// <param name="packet">Packet ref you got from server</param>
19- public static bool CheckForApiKey ( List < string > keys , ref Packet packet )
20+ public static bool CheckForApiKey ( List < string > keys , HttpListenerContext context )
2021{
2122try
2223{
23- if ( GetApiKey ( out string ? _key , ref packet ) )
24+ if ( GetApiKey ( out string ? _key , context ) )
2425foreach ( var key in keys )
2526{
2627if ( _key == key )
@@ -41,11 +42,11 @@ public static bool CheckForApiKey(List<string> keys, ref Packet packet)
4142/// <param name="credentialsList">List of all usernames and passwords authorized</param>
4243/// <param name="hashingFunction">Password hashing algorithm. Takes un-hashed password as parameter, returns hashed password</param>
4344/// <param name="packet">Packet ref you got from server</param>
44- public static bool CheckForBasicCredentials ( List < BasicCredentials > credentialsList , Func < string , string > hashingFunction , ref Packet packet )
45+ public static bool CheckForBasicCredentials ( List < BasicCredentials > credentialsList , Func < string , string > hashingFunction , HttpListenerContext context )
4546{
4647try
4748{
48- if ( GetBasicCredentials ( out BasicCredentials ? credentials , ref packet ) )
49+ if ( GetBasicCredentials ( out BasicCredentials ? credentials , context ) )
4950{
5051credentials . HashedPassword = hashingFunction ( credentials . Password ) ;
5152foreach ( BasicCredentials _credentials in credentialsList )
@@ -63,9 +64,9 @@ public static bool CheckForBasicCredentials(List<BasicCredentials> credentialsLi
6364return false ;
6465}
6566
66- public static bool GetApiKey ( out string ? key , ref Packet packet )
67+ public static bool GetApiKey ( out string ? key , HttpListenerContext context )
6768{
68- key = packet . Request . Headers . Get ( "x-api-key" ) ;
69+ key = context . Request . Headers . Get ( "x-api-key" ) ;
6970
7071if ( key is null )
7172return false ;
@@ -78,14 +79,14 @@ public static bool GetApiKey(out string? key, ref Packet packet)
7879/// </summary>
7980/// <param name="credentials">Variable contains passed user credentials</param>
8081/// <param name="packet">Packet ref you got from server</param>
81- public static bool GetBasicCredentials ( out BasicCredentials ? credentials , ref Packet packet )
82+ public static bool GetBasicCredentials ( out BasicCredentials ? credentials , HttpListenerContext context )
8283{
8384credentials = null ;
8485try
8586{
86- if ( packet . Request . Headers . Get ( "Authorization" ) . Contains ( "Basic " ) )
87+ if ( context . Request . Headers . Get ( "Authorization" ) . Contains ( "Basic " ) )
8788{
88- string authData = packet . Request . Headers . GetValues ( "Authorization" ) . GetValue ( 0 ) . ToString ( ) . Substring ( 6 ) ;
89+ string authData = context . Request . Headers . GetValues ( "Authorization" ) . GetValue ( 0 ) . ToString ( ) . Substring ( 6 ) ;
8990
9091byte [ ] decodedBase64 = Convert . FromBase64String ( authData ) ;
9192
0 commit comments