예제 #1
0
    public OAuthClient(IHttpClientFactory httpClientFactory, OAuthClientConfiguration configuration)
    {
        var httpClient = httpClientFactory.CreateClient(nameof(OAuthClient));

        httpClient.BaseAddress = new Uri(configuration.BaseUri);

        _httpClient    = httpClient;
        _configuration = configuration;
    }
예제 #2
0
        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));
        }
예제 #3
0
 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);
    }
예제 #5
0
    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)));
        }
예제 #7
0
 public OAuthController(IOAuthFlowsFactory oAuthFlowsFactory, IOptionsMonitor <OAuthClientConfiguration> optionsMonitor)
 {
     _oAuthClientConfiguration = optionsMonitor.GetEx(OAuthConfigurationNames.Github);
     _oAuthFlows = oAuthFlowsFactory.CreateOAuthFlows(OAuthConfigurationNames.Github);
 }
예제 #8
0
 public static Uri GetAuthorizeEndpointUri(OAuthClientConfiguration config)
 {
     return(new Uri(new Uri(config.AuthorizationServerRootUri), "./connect/authorize"));
 }
예제 #9
0
 public static Uri GetPermissionsEndpointUri(OAuthClientConfiguration config)
 {
     return(new Uri(new Uri(config.AuthorizationServerRootUri), "./permissions"));
 }
예제 #10
0
 public static Uri GetIdentityTokenValidationEndpointUri(OAuthClientConfiguration config)
 {
     return(new Uri(new Uri(config.AuthorizationServerRootUri), "./connect/identitytokenvalidation"));
 }
예제 #11
0
 public static Uri GetUserInfoEndpointUri(OAuthClientConfiguration config)
 {
     return(new Uri(new Uri(config.AuthorizationServerRootUri), "./connect/userinfo"));
 }
예제 #12
0
 public static Uri GetLogoutEndpointUri(OAuthClientConfiguration config)
 {
     return(new Uri(new Uri(config.AuthorizationServerRootUri), "./connect/endsession"));
 }