public OAuthClient(IHttpClientFactory httpClientFactory, OAuthClientConfiguration configuration) { var httpClient = httpClientFactory.CreateClient(nameof(OAuthClient)); httpClient.BaseAddress = new Uri(configuration.BaseUri); _httpClient = httpClient; _configuration = configuration; }
public ActionResult Index(OAuthClientConfiguration model) { var state = Guid.NewGuid().ToString("N"); var nonce = Guid.NewGuid().ToString("N"); SetTempState(state, nonce); DefaultClientConfiguration.CurrentOAuthConfig = model; var url = CreateCodeFlowUrl(state, nonce); return(Redirect(url)); }
public async Task <IOAuthClientResponse> RunFlow( OAuthClientConfiguration oAuthClientConfiguration, AuthorizationCodeResponse authorizationCodeResponse = null, ImplicitFlowResponse implicitFlowResponse = null, DeviceCodeResponse deviceCodeResponse = null, string originalState = null, string codeVerifier = null) { return(oAuthClientConfiguration.FlowType switch { FlowTypes.AuthorizationCode => await RunAuthorizationCodeFlow(authorizationCodeResponse, originalState), FlowTypes.AuthorizationCodeWithPKCE => await RunAuthorizationCodeWithPkceFlow(authorizationCodeResponse, originalState, codeVerifier), FlowTypes.Implicit => RunImplicitFlow(implicitFlowResponse, originalState), FlowTypes.Device => await RunDeviceFlow(deviceCodeResponse), _ => null });
public static IServiceCollection AddOAuthClient(this IServiceCollection services, IConfiguration configuration) { var oAuthClientConfigurations = configuration.GetSection(ConfigurationConstants.RootSectionName) .Get <List <OAuthClientConfiguration> >(); if (!oAuthClientConfigurations.Any()) { var oauthClientConfiguration = new OAuthClientConfiguration(); configuration.Bind(ConfigurationConstants.RootSectionName, oauthClientConfiguration); services.AddSingleton(oauthClientConfiguration); services .AddOptions <OAuthClientConfiguration>() .Bind(configuration.GetSection(ConfigurationConstants.RootSectionName)); services .AddOptions <OAuthClientConfiguration>(oauthClientConfiguration.Name.ToLower()) .Bind(configuration.GetSection(ConfigurationConstants.RootSectionName)); } else { services.AddScoped(_ => new OAuthClientConfiguration()); for (var i = 0; i < oAuthClientConfigurations.Count; i++) { services .AddOptions <OAuthClientConfiguration>(oAuthClientConfigurations[i].Name.ToLower()) .Bind(configuration.GetSection($"{ConfigurationConstants.RootSectionName}:{i}")); } } services.AddHttpClient(nameof(OAuthClient), httpClient => { httpClient.DefaultRequestHeaders.Add("Accept", "application/vnd.github.v3+json"); httpClient.DefaultRequestHeaders.Add("User-Agent", "localhost"); }); services.AddScoped <IOAuthClient, OAuthClient>(); services.AddScoped <IOAuthFlows, OAuthFlows>(); services.AddScoped <IOAuthClientFactory, OAuthClientFactory>(); services.AddScoped <IOAuthFlowsFactory, OAuthFlowsFactory>(); return(services); }
public async Task <IOAuthClientResponse> RunFlow( OAuthClientConfiguration oAuthClientConfiguration, string state = null, string username = null, string password = null, string responseMode = null) { var response = oAuthClientConfiguration.FlowType switch { FlowTypes.AuthorizationCode => RunAuthorizationCodeFlow(oAuthClientConfiguration.Scopes, state), FlowTypes.AuthorizationCodeWithPKCE => RunAuthorizationCodeWithPkceFlow(oAuthClientConfiguration.Scopes, state), FlowTypes.Implicit => RunImplicitFlow(oAuthClientConfiguration.Scopes, state, responseMode), FlowTypes.ClientCredentials => await RunClientCredentialsFlow(oAuthClientConfiguration.Scopes), FlowTypes.Password => await RunPasswordFlow(username, password, oAuthClientConfiguration.Scopes), FlowTypes.Device => await RunDeviceFlow(oAuthClientConfiguration.Scopes) }; return(response); }
public static Uri GetArloAuthApiTestResourceUri(OAuthClientConfiguration config) { string apiHost = new Uri(config.AuthorizationServerRootUri).DnsSafeHost; return(new Uri(string.Format("https://{0}/{1}/api/2012-02-01/auth/resources/events/", apiHost, config.Tenant))); }
public OAuthController(IOAuthFlowsFactory oAuthFlowsFactory, IOptionsMonitor <OAuthClientConfiguration> optionsMonitor) { _oAuthClientConfiguration = optionsMonitor.GetEx(OAuthConfigurationNames.Github); _oAuthFlows = oAuthFlowsFactory.CreateOAuthFlows(OAuthConfigurationNames.Github); }
public static Uri GetAuthorizeEndpointUri(OAuthClientConfiguration config) { return(new Uri(new Uri(config.AuthorizationServerRootUri), "./connect/authorize")); }
public static Uri GetPermissionsEndpointUri(OAuthClientConfiguration config) { return(new Uri(new Uri(config.AuthorizationServerRootUri), "./permissions")); }
public static Uri GetIdentityTokenValidationEndpointUri(OAuthClientConfiguration config) { return(new Uri(new Uri(config.AuthorizationServerRootUri), "./connect/identitytokenvalidation")); }
public static Uri GetUserInfoEndpointUri(OAuthClientConfiguration config) { return(new Uri(new Uri(config.AuthorizationServerRootUri), "./connect/userinfo")); }
public static Uri GetLogoutEndpointUri(OAuthClientConfiguration config) { return(new Uri(new Uri(config.AuthorizationServerRootUri), "./connect/endsession")); }