Пример #1
0
        public async Task <ActionResult <OIDCConfig> > ConfigurationAsync()
        {
            OIDCConfig    config    = new OIDCConfig();
            OidcWellKnown wellKnown = await GetWellKnownAsync();

            string protocol = Request.IsHttps ? "https://" : "http://";

            config.stsServer     = $"{protocol}{Request.Host.ToUriComponent()}/api/config";
            config.redirect_url  = $"{protocol}{Request.Host.ToUriComponent()}/";
            config.client_id     = _configuration["oidc:client_id"];
            config.response_type = "id_token token";
            if (!String.IsNullOrEmpty(_configuration["oidc:scope"]))
            {
                config.scope = _configuration["oidc:scope"];
            }
            else
            {
                config.scope = "openid profile email https://graph.microsoft.com/User.Read";
            }
            config.post_logout_redirect_uri   = $"{protocol}{Request.Host.ToUriComponent()}/";
            config.post_login_route           = "/home";
            config.forbidden_route            = "/home";
            config.unauthorized_route         = "/home";
            config.auto_userinfo              = false;
            config.log_console_warning_active = true;
            config.log_console_debug_active   = _env.IsDevelopment();
            config.max_id_token_iat_offset_allowed_in_seconds = 1000;
            if (!String.IsNullOrEmpty(_configuration["oidc:resource"]))
            {
                config.additional_login_parameters["resource"] = _configuration["oidc:resource"];
            }
            return(config);
        }
Пример #2
0
        private async Task <OidcWellKnown> GetWellKnownAsync()
        {
            if (_wellKnown == null)
            {
                var client = new HttpClient();
                client.BaseAddress = new Uri(_configuration["oidc:issuer"]);
                client.DefaultRequestHeaders.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                HttpResponseMessage response = await client.GetAsync(".well-known/openid-configuration");

                if (response.IsSuccessStatusCode)
                {
                    _wellKnown = await response.Content.ReadAsAsync <OidcWellKnown>();
                }
            }
            return(_wellKnown);
        }
Пример #3
0
        private async Task <OidcWellKnown> GetWellKnownAsync()
        {
            if (this.wellKnown == null)
            {
                var client = new HttpClient();
                client.BaseAddress = new Uri(this.configuration["Oidc:Authority"] + "/");
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                var response = await client.GetAsync(".well-known/openid-configuration").ConfigureAwait(false);

                if (response.IsSuccessStatusCode)
                {
                    var wellknownString = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                    this.wellKnown = JsonConvert.DeserializeObject <OidcWellKnown>(wellknownString);
                }
            }
            return(this.wellKnown);
        }