public override Task <AuthorizationServerConfiguration> GetConfigurationAsync(string federationPartyId, CancellationToken cancel) { AuthorizationServerConfiguration configuration = null; var key = ORMAuthorizationServerConfigurationManager.FormatKey(federationPartyId); if (this._cacheProvider.Contains(key)) { configuration = this._cacheProvider.Get <AuthorizationServerConfiguration>(key); } else { var model = this._dbContext.Set <AuthorizationServerModel>() .Select(x => new { x, x.FederationPartySettings.FederationPartyId }) .FirstOrDefault(x => x.FederationPartyId == federationPartyId); if (model != null) { configuration = new AuthorizationServerConfiguration { CreateToken = model.x.UseTokenAuthorisation, TokenResponseUrl = String.IsNullOrWhiteSpace(model.x.TokenResponseUrl) ? null : new Uri(model.x.TokenResponseUrl) }; this._cacheProvider.Put(key, configuration); } } return(Task.FromResult(configuration)); }
private async Task <bool> TryTokenEndpointResponse(AuthenticationTokenCreateContext context, IDictionary <string, object> relayState, AuthorizationServerConfiguration configuration) { IAuthorizationServerProvider authorizationServerProvider; if (!this._resolver.TryResolve <IAuthorizationServerProvider>(out authorizationServerProvider)) { return(false); } var sSOTokenEndpointResponseContext = new SSOTokenEndpointResponseContext(base.Context, base.Options, context.Token, context.Ticket, relayState, configuration); await authorizationServerProvider.TokenEndpointResponse(sSOTokenEndpointResponseContext); return(sSOTokenEndpointResponseContext.IsRequestCompleted); }
private bool TryCreateToken(AuthenticationTicket ticket, IDictionary <string, object> relayState, out AuthenticationTokenCreateContext context, out AuthorizationServerConfiguration configuration) { context = null; if (!relayState.ContainsKey(RelayStateContstants.FederationPartyId)) { throw new InvalidOperationException("Federation party id is not in the relay state."); } var federationPartyId = relayState[RelayStateContstants.FederationPartyId].ToString(); var configurationManager = this._resolver.Resolve <IConfigurationManager <AuthorizationServerConfiguration> >(); var configurationTask = configurationManager.GetConfigurationAsync(federationPartyId, CancellationToken.None); configurationTask.Wait(); configuration = configurationTask.Result; //if no configuration for the parner return, no need to throw an exception. if (configuration == null || !configuration.CreateToken) { return(false); } ISecureDataFormat <AuthenticationTicket> dataFormat; if (!this._resolver.TryResolve <ISecureDataFormat <AuthenticationTicket> >(out dataFormat)) { return(false); } context = new AuthenticationTokenCreateContext(base.Context, dataFormat, ticket); IAuthenticationTokenProvider authenticationTokenProvider; if (!this._resolver.TryResolve <IAuthenticationTokenProvider>(out authenticationTokenProvider)) { return(false); } authenticationTokenProvider.Create(context); return(true); }
public SSOTokenEndpointResponseContext(IOwinContext context, SSOAuthenticationOptions options, string token, AuthenticationTicket ticket, IDictionary <string, object> relayState, AuthorizationServerConfiguration configuration) : base(context, options) { this.Token = token; this.Ticket = ticket; this.RelayState = relayState; this.Configuration = configuration; }