add handler to authentication check
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
namespace Pilz.Net.Api;
|
||||
|
||||
public class ApiAuthCheckEventArgs(string authKey) : EventArgs
|
||||
public class ApiAuthCheckEventArgs(string authKey, Delegate? handler) : EventArgs
|
||||
{
|
||||
private bool hasDenyed;
|
||||
|
||||
public Delegate? Handler { get; }
|
||||
|
||||
public string AuthKey { get; } = authKey;
|
||||
|
||||
public bool Valid { get; set; }
|
||||
|
||||
@@ -205,7 +205,7 @@ public class ApiServer(string apiUrl) : IApiServer
|
||||
Log.Debug("Check authentication");
|
||||
var isAuthenticated = false;
|
||||
if (!string.IsNullOrWhiteSpace(authKey) && DecodeAuthKey(authKey) is string authKeyDecoded)
|
||||
isAuthenticated = CheckAuthentication(authKeyDecoded);
|
||||
isAuthenticated = CheckAuthentication(authKeyDecoded, handler);
|
||||
else
|
||||
authKeyDecoded = null!;
|
||||
if (attribute.RequiesAuth && !isAuthenticated)
|
||||
@@ -278,11 +278,11 @@ public class ApiServer(string apiUrl) : IApiServer
|
||||
return Serializer;
|
||||
}
|
||||
|
||||
protected virtual bool CheckAuthentication(string authKey)
|
||||
protected virtual bool CheckAuthentication(string authKey, Delegate? handler)
|
||||
{
|
||||
if (OnCheckAuthentication != null)
|
||||
{
|
||||
var args = new ApiAuthCheckEventArgs(authKey);
|
||||
var args = new ApiAuthCheckEventArgs(authKey, handler);
|
||||
OnCheckAuthentication?.Invoke(this, args);
|
||||
return args.Valid;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user