public ServicesController(IServiceProxyProvider serviceProxyProvider, IServiceRouteProvider serviceRouteProvider, IAuthorizationServerProvider authorizationServerProvider, IServicePartProvider servicePartProvider) { _serviceProxyProvider = serviceProxyProvider; _serviceRouteProvider = serviceRouteProvider; _authorizationServerProvider = authorizationServerProvider; _servicePartProvider = servicePartProvider; }
public ServicesController(IServiceProxyProvider serviceProxyProvider, IServiceRouteProvider serviceRouteProvider, IAuthorizationServerProvider authorizationServerProvider, IStringLocalizer <ServicesController> servicesLocalizer) { _serviceProxyProvider = serviceProxyProvider; _serviceRouteProvider = serviceRouteProvider; _authorizationServerProvider = authorizationServerProvider; _servicesLocalizer = servicesLocalizer; }
/// <summary> /// Initializes a new instance of the <see cref="BearerTokenModule"/> class. /// </summary> /// <param name="authorizationServerProvider">The authorization server provider.</param> /// <param name="routes">The routes.</param> /// <param name="secretKey">The secret key.</param> /// <param name="endpoint">The endpoint.</param> public BearerTokenModule( IAuthorizationServerProvider authorizationServerProvider, IEnumerable <string> routes = null, SymmetricSecurityKey secretKey = null, string endpoint = "/token") { // TODO: Make secretKey parameter mandatory and and an overload that takes in a string for a secretKey SecretKey = secretKey ?? new SymmetricSecurityKey(Encoding.UTF8.GetBytes("0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9eyJjbGF")); AddHandler(endpoint, HttpVerbs.Post, async(context, ct) => { var validationContext = context.GetValidationContext(); await authorizationServerProvider.ValidateClientAuthentication(validationContext); if (validationContext.IsValidated) { await context.JsonResponseAsync(new BearerToken { Token = validationContext.GetToken(SecretKey), TokenType = "bearer", ExpirationDate = authorizationServerProvider.GetExpirationDate(), Username = validationContext.IdentityName, }); } else { context.Rejected(); } return(true); }); AddHandler(ModuleMap.AnyPath, HttpVerbs.Any, (context, ct) => { if (routes != null) { var match = Match(routes, context); if (!match) { return(Task.FromResult(false)); } } // decode token to see if it's valid if (context.GetSecurityToken(SecretKey) != null) { return(Task.FromResult(false)); } context.Rejected(); return(Task.FromResult(true)); }); }
/// <summary> /// Initializes a new instance of the <see cref="BearerTokenModule" /> class. /// </summary> /// <param name="baseUrlPath">The base URL path.</param> /// <param name="authorizationServerProvider">The authorization server provider.</param> /// <param name="secretKey">The secret key.</param> /// <param name="endpoint">The endpoint for the authorization (relative to baseUrlPath).</param> public BearerTokenModule( string baseUrlPath, IAuthorizationServerProvider authorizationServerProvider, SymmetricSecurityKey secretKey, string endpoint = "/token") : base(baseUrlPath) { SecretKey = secretKey ?? new SymmetricSecurityKey(Encoding.UTF8.GetBytes("0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9eyJjbGF")); _tokenEndpoint = endpoint; _authorizationServerProvider = authorizationServerProvider; }
/// <summary> /// Fluent-like method to attach BearerToken. /// </summary> /// <param name="webserver">The webserver.</param> /// <param name="authorizationProvider">The authorization provider.</param> /// <param name="routes">The routes.</param> /// <param name="secretKey">The secret key.</param> /// <returns>The same web server.</returns> public static IWebServer UseBearerToken(this IWebServer webserver, IAuthorizationServerProvider authorizationProvider = null, IEnumerable <string> routes = null, SymmetricSecurityKey secretKey = null) { webserver.RegisterModule( new BearerTokenModule( authorizationProvider ?? new BasicAuthorizationServerProvider(), routes, secretKey)); return(webserver); }
public AuthController() /* IServiceProxyProvider serviceProxyProvider, * IServiceRouteProvider serviceRouteProvider, * IAuthorizationServerProvider authorizationServerProvider) */ { // ServiceLocator.GetService<IServiceProxyProvider>(); // //_serviceProxyProvider = serviceProxyProvider; //_serviceRouteProvider = serviceRouteProvider; //_authorizationServerProvider = authorizationServerProvider; _serviceProxyProvider = ServiceLocator.GetService <IServiceProxyProvider>(); _serviceRouteProvider = ServiceLocator.GetService <IServiceRouteProvider>(); //serviceRouteProvider; _authorizationServerProvider = ServiceLocator.GetService <IAuthorizationServerProvider>(); // authorizationServerProvider; }
/// <summary> /// Initializes a new instance of the <see cref="BearerTokenModule" /> class. /// </summary> /// <param name="baseUrlPath">The base URL path.</param> /// <param name="authorizationServerProvider">The authorization server provider.</param> /// <param name="secretKeyString">The secret key string.</param> /// <param name="endpoint">The endpoint for the authorization (relative to baseUrlPath).</param> /// <exception cref="ArgumentNullException">secretKeyString</exception> /// <exception cref="ArgumentException">A key must be 40 chars.</exception> public BearerTokenModule( string baseUrlPath, IAuthorizationServerProvider authorizationServerProvider, string secretKeyString, string endpoint = "/token") : this( baseUrlPath, authorizationServerProvider, new SymmetricSecurityKey(Encoding.UTF8.GetBytes(secretKeyString)), endpoint) { if (secretKeyString == null) { throw new ArgumentNullException(nameof(secretKeyString)); } if (secretKeyString.Length != 40) { throw new ArgumentException("A key must be 40 chars"); } }
public AuthorizationFilterAttribute() { _authorizationServerProvider = ServiceLocator.Current.Resolve <IAuthorizationServerProvider>(); }
public ServicesController() { _serviceProxyProvider = ServiceLocator.GetService <IServiceProxyProvider>(); _serviceRouteProvider = ServiceLocator.GetService <IServiceRouteProvider>(); _authorizationServerProvider = ServiceLocator.GetService <IAuthorizationServerProvider>(); }
/// <summary> /// Module's Constructor /// </summary> /// <param name="authorizationServerProvider">The AuthorizationServerProvider to use</param> /// <param name="routes">The routes to authorizate</param> /// <param name="secretKey">The secret key to encrypt tokens</param> public BearerTokenModule(IAuthorizationServerProvider authorizationServerProvider, IEnumerable <string> routes = null, string secretKey = "0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9eyJjbGF") { AddHandler("/token", HttpVerbs.Post, (server, context) => { var validationContext = context.GetValidationContext(); authorizationServerProvider.ValidateClientAuthentication(validationContext); if (validationContext.IsValidated) { context.JsonResponse(new BearerToken { Token = validationContext.GetToken(secretKey), TokenType = "bearer", ExpirationDate = authorizationServerProvider.GetExpirationDate(), Username = validationContext.ClientId }); } else { context.Rejected(); } return(true); }); AddHandler(ModuleMap.AnyPath, HttpVerbs.Any, (server, context) => { if (routes != null && routes.Contains(context.RequestPath()) == false) { return(false); } var authHeader = context.RequestHeader(AuthorizationHeader); if (string.IsNullOrWhiteSpace(authHeader) == false && authHeader.StartsWith("Bearer ")) { try { var token = authHeader.Replace("Bearer ", ""); var payload = JWT.JsonWebToken.DecodeToObject(token, secretKey) as IDictionary <string, object>; if (payload == null || payload.Count == 0) { throw new Exception("Invalid token"); } return(false); } catch (JWT.SignatureVerificationException) { server.Log.DebugFormat("Invalid token {0}", authHeader); throw; } catch (Exception ex) { server.Log.Error(ex); } } context.Rejected(); return(true); }); }
public ActionFilterAttribute(IHttpContextAccessor httpContextAccessor) { _httpContextAccessor = httpContextAccessor; _authorizationServerProvider = ServiceLocator.Current.Resolve <IAuthorizationServerProvider>(); }