mirror of
https://github.com/cadmium-im/zirconium-sharp.git
synced 2024-11-08 11:41:04 +00:00
Implement setting default auth provider by config
This commit is contained in:
parent
370a7e8dc2
commit
9e0088cbba
@ -29,6 +29,7 @@ namespace Zirconium.Core
|
||||
Database = new DatabaseConnector(this);
|
||||
PluginManager = new PluginManager(PluginHostAPI);
|
||||
PluginManager.LoadPlugins(config.PluginsDirPath, config.EnabledPlugins);
|
||||
AuthManager.SetDefaultAuthProvider();
|
||||
Log.Info("Zirconium is initialized successfully");
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ using JWT.Builder;
|
||||
using Newtonsoft.Json;
|
||||
using Zirconium.Utils;
|
||||
using Zirconium.Core.Plugins.Interfaces;
|
||||
using System.Linq;
|
||||
|
||||
namespace Zirconium.Core
|
||||
{
|
||||
@ -14,13 +15,13 @@ namespace Zirconium.Core
|
||||
private string _secretString;
|
||||
private const long DEFAULT_TOKEN_EXPIRATION_TIME_HOURS = 24 * 3600000;
|
||||
private IList<IAuthProvider> _authProviders;
|
||||
private IAuthProvider _defaultAuthProvider;
|
||||
public IAuthProvider DefaultAuthProvider { get; private set; }
|
||||
|
||||
public AuthManager(App app)
|
||||
{
|
||||
_app = app;
|
||||
_authProviders = new List<IAuthProvider>();
|
||||
_defaultAuthProvider = null;
|
||||
DefaultAuthProvider = null;
|
||||
_secretString = Guid.NewGuid().ToString();
|
||||
}
|
||||
|
||||
@ -37,7 +38,8 @@ namespace Zirconium.Core
|
||||
.Encode();
|
||||
}
|
||||
|
||||
public string CreateToken(string entityID, string deviceID) {
|
||||
public string CreateToken(string entityID, string deviceID)
|
||||
{
|
||||
return CreateToken(entityID, deviceID, DEFAULT_TOKEN_EXPIRATION_TIME_HOURS);
|
||||
}
|
||||
|
||||
@ -49,17 +51,23 @@ namespace Zirconium.Core
|
||||
.MustVerifySignature()
|
||||
.Decode(token);
|
||||
var payload = JsonConvert.DeserializeObject<JWTPayload>(jsonPayload);
|
||||
if (_defaultAuthProvider == null) {
|
||||
if (DefaultAuthProvider == null)
|
||||
{
|
||||
throw new Exception("Default auth provider isn't specified");
|
||||
}
|
||||
var validToken = _defaultAuthProvider.TestToken(token, payload);
|
||||
var validToken = DefaultAuthProvider.TestToken(token, payload);
|
||||
if (!validToken)
|
||||
return null;
|
||||
return payload;
|
||||
}
|
||||
|
||||
public void AddAuthProvider(IAuthProvider provider) {
|
||||
public void AddAuthProvider(IAuthProvider provider)
|
||||
{
|
||||
_authProviders.Add(provider);
|
||||
}
|
||||
|
||||
public void SetDefaultAuthProvider() {
|
||||
DefaultAuthProvider = _authProviders.Where(x => x.GetAuthProviderName() == _app.Config.AuthenticationProvider).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
}
|
@ -12,12 +12,14 @@ namespace Zirconium.Core.Plugins.Interfaces
|
||||
void UnhookCoreEvent(ICoreEventHandler handler);
|
||||
void FireEvent(CoreEvent coreEvent);
|
||||
string GenerateAuthToken(string entityID, string deviceID, int tokenExpirationMillis);
|
||||
string GenerateAuthToken(string entityID, string deviceID);
|
||||
string[] GetServerDomains();
|
||||
string GetServerID();
|
||||
void SendMessage(Session session, BaseMessage message);
|
||||
dynamic GetSettings(IPluginAPI plugin);
|
||||
dynamic GetSettings(string pluginName);
|
||||
void ProvideAuth(IAuthProvider provider);
|
||||
IAuthProvider GetAuthProvider();
|
||||
IExposedSessionManager GetSessionManager();
|
||||
void RegisterIPCService(IPluginAPI plugin, dynamic service);
|
||||
Task<dynamic> MakeIPCRequest(string pluginName, string methodName, dynamic paramsObject);
|
||||
|
@ -102,5 +102,15 @@ namespace Zirconium.Core.Plugins
|
||||
{
|
||||
return _app.Database.MongoDatabase;
|
||||
}
|
||||
|
||||
public IAuthProvider GetAuthProvider()
|
||||
{
|
||||
return _app.AuthManager.DefaultAuthProvider;
|
||||
}
|
||||
|
||||
public string GenerateAuthToken(string entityID, string deviceID)
|
||||
{
|
||||
return _app.AuthManager.CreateToken(entityID, deviceID);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user