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