1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- using System;
- using Wicture.DbRESTFul.Configuration;
- using Wicture.DbRESTFul.Resources.Api;
- namespace Wicture.DbRESTFul.Authentication
- {
- public class DefaultTokenOptionsProvider : ITokenOptionsProvider
- {
- private readonly ISectionConfigProvider _sectionConfigProvider;
- private static TokenOptions _default = new TokenOptions()
- {
- TokenRequestPath = "/token",
- RefreshTokenRequestPath = "/token/refresh",
- SecretKey = "Wicture@Micr0serv!ces^Secretkeys", //"Wicture@Micr0serv!ce^Secret",
- Audience = "DbRESTFulApi",
- Issuer = "Wicture",
- CookieName = "access_token",
- UseJwtCookie = true,
- Expiration = TimeSpan.FromHours(24),
- LoginSchema = new Schema[]
- {
- new Schema { name = "username", nullable = false, type = SchemaType.String },
- new Schema { name = "password", nullable = false, type = SchemaType.String },
- new Schema { name = "tag", nullable = true, type = SchemaType.String }
- }
- };
- public DefaultTokenOptionsProvider(ISectionConfigProvider sectionConfigProvider)
- {
- _sectionConfigProvider = sectionConfigProvider;
- }
- public virtual TokenOptions Provide()
- {
- var option = _sectionConfigProvider.Provide<TokenOptions>();
- if (option == null) return _default;
- if (string.IsNullOrEmpty(option.TokenRequestPath)) option.TokenRequestPath = _default.TokenRequestPath;
- if (string.IsNullOrEmpty(option.RefreshTokenRequestPath)) option.RefreshTokenRequestPath = _default.RefreshTokenRequestPath;
- if (string.IsNullOrEmpty(option.SecretKey)) option.SecretKey = _default.SecretKey;
- if (string.IsNullOrEmpty(option.Audience)) option.Audience = _default.Audience;
- if (string.IsNullOrEmpty(option.Issuer)) option.Issuer = _default.Issuer;
- if (option.Expiration == default) option.Expiration = _default.Expiration;
- if (!(option.LoginSchema?.Length > 0)) option.LoginSchema = _default.LoginSchema;
- return option;
- }
- }
- }
|