Esempio n. 1
0
        protected override Task ApplyResponseChallengeAsync()
        {
            if (Response.StatusCode != 401)
            {
                return(Task.FromResult <object>(null));
            }

            AuthenticationResponseChallenge challenge = Helper.LookupChallenge(Options.AuthenticationType, Options.AuthenticationMode);

            if (challenge != null)
            {
                string requestPrefix = Request.Scheme + Uri.SchemeDelimiter + Request.Host;

                var state = challenge.Properties;
                if (String.IsNullOrEmpty(state.RedirectUri))
                {
                    state.RedirectUri = requestPrefix + Request.PathBase + Request.Path + Request.QueryString;
                }

                // Anti-CSRF
                GenerateCorrelationId(state);

                string returnTo = BuildReturnTo(Options.StateDataFormat.Protect(state));

                string authorizationEndpoint =
                    "https://www.google.com/accounts/o8/ud" +
                    "?openid.ns=" + Uri.EscapeDataString("http://specs.openid.net/auth/2.0") +
                    "&openid.ns.ax=" + Uri.EscapeDataString("http://openid.net/srv/ax/1.0") +
                    "&openid.mode=" + Uri.EscapeDataString("checkid_setup") +
                    "&openid.claimed_id=" + Uri.EscapeDataString("http://specs.openid.net/auth/2.0/identifier_select") +
                    "&openid.identity=" + Uri.EscapeDataString("http://specs.openid.net/auth/2.0/identifier_select") +
                    "&openid.return_to=" + Uri.EscapeDataString(returnTo) +
                    "&openid.realm=" + Uri.EscapeDataString(requestPrefix) +
                    "&openid.ax.mode=" + Uri.EscapeDataString("fetch_request") +
                    "&openid.ax.type.email=" + Uri.EscapeDataString("http://axschema.org/contact/email") +
                    "&openid.ax.type.name=" + Uri.EscapeDataString("http://axschema.org/namePerson") +
                    "&openid.ax.type.first=" + Uri.EscapeDataString("http://axschema.org/namePerson/first") +
                    "&openid.ax.type.last=" + Uri.EscapeDataString("http://axschema.org/namePerson/last") +
                    "&openid.ax.required=" + Uri.EscapeDataString("email,name,first,last");

                var redirectContext = new GoogleApplyRedirectContext(
                    Context, Options,
                    state, authorizationEndpoint);
                Options.Provider.ApplyRedirect(redirectContext);
            }

            return(Task.FromResult <object>(null));
        }
Esempio n. 2
0
 /// <summary>
 /// Called when a Challenge causes a redirect to authorize endpoint in the Google OpenID middleware
 /// </summary>
 /// <param name="context">Contains redirect URI and <see cref="AuthenticationProperties"/> of the challenge </param>
 public virtual void ApplyRedirect(GoogleApplyRedirectContext context)
 {
     OnApplyRedirect(context);
 }