Esempio n. 1
0
        // TODO: Abstract this properties override pattern into the base class?
        protected override string BuildChallengeUrl(AuthenticationProperties properties, string redirectUri)
        {
            var scope = FormatScope();

            var    tenantOptions       = new MultiTenantGoogleOptionsResolver(Options, siteResolver, siteRepo, multiTenantOptions);
            string resolvedRedirectUri = tenantOptions.ResolveRedirectUrl(redirectUri);

            log.LogDebug("resolvedRedirectUri was " + resolvedRedirectUri);

            var queryStrings = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            queryStrings.Add("response_type", "code");
            //queryStrings.Add("client_id", Options.ClientId);
            //queryStrings.Add("redirect_uri", redirectUri);
            queryStrings.Add("client_id", tenantOptions.ClientId);
            queryStrings.Add("redirect_uri", resolvedRedirectUri);

            AddQueryString(queryStrings, properties, "scope", scope);

            AddQueryString(queryStrings, properties, "access_type", Options.AccessType);
            AddQueryString(queryStrings, properties, "approval_prompt");
            AddQueryString(queryStrings, properties, "login_hint");

            var state = Options.StateDataFormat.Protect(properties);

            queryStrings.Add("state", state);

            var authorizationEndpoint = QueryHelpers.AddQueryString(Options.AuthorizationEndpoint, queryStrings);

            return(authorizationEndpoint);
        }
Esempio n. 2
0
        protected override async Task <OAuthTokenResponse> ExchangeCodeAsync(string code, string redirectUri)
        {
            log.LogDebug("ExchangeCodeAsync called with code " + code + " redirectUri " + redirectUri);


            //var tokenRequestParameters = new Dictionary<string, string>()
            //{
            //    { "client_id", Options.ClientId },
            //    { "redirect_uri", redirectUri },
            //    { "client_secret", Options.ClientSecret },
            //    { "code", code },
            //    { "grant_type", "authorization_code" },
            //};

            var currentSite = await GetSite();

            var tenantOptions = new MultiTenantGoogleOptionsResolver(
                Options,
                currentSite,
                multiTenantOptions);

            var tokenRequestParameters = new Dictionary <string, string>()
            {
                { "client_id", tenantOptions.ClientId },
                { "redirect_uri", tenantOptions.ResolveRedirectUrl(redirectUri) },
                { "client_secret", tenantOptions.ClientSecret },
                { "code", code },
                { "grant_type", "authorization_code" },
            };

            var requestContent = new FormUrlEncodedContent(tokenRequestParameters);

            var requestMessage = new HttpRequestMessage(HttpMethod.Post, Options.TokenEndpoint);

            requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            requestMessage.Content = requestContent;
            var response = await Backchannel.SendAsync(requestMessage, Context.RequestAborted);

            response.EnsureSuccessStatusCode();
            var payload = JObject.Parse(await response.Content.ReadAsStringAsync());

            return(new OAuthTokenResponse(payload));
        }