コード例 #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 baseUri =
                    Request.Scheme +
                    Uri.SchemeDelimiter +
                    Request.Host +
                    Request.PathBase;

                string currentUri =
                    baseUri +
                    Request.Path +
                    Request.QueryString;

                string redirectUri =
                    baseUri +
                    Options.CallbackPath;

                AuthenticationProperties properties = challenge.Properties;
                if (string.IsNullOrEmpty(properties.RedirectUri))
                {
                    properties.RedirectUri = currentUri;
                }

                // comma separated
                string scope = string.Join(",", Options.Scope);

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

                string authorizationEndpoint =
                    string.Format(AuthorizeEndpoint, Options.Domain) +
                    "?client_id=" + Uri.EscapeDataString(Options.ClientId) +
                    "&connection=" + Uri.EscapeDataString(Options.Connection ?? string.Empty) +
                    "&response_type=code" +
                    "&redirect_uri=" + Uri.EscapeDataString(redirectUri) +
                    "&state=" + Uri.EscapeDataString(state) +
                    (Options.Scope.Count > 0 ? "&scope=" + Uri.EscapeDataString(string.Join(" ", Options.Scope)) : string.Empty);

                var redirectContext = new Auth0ApplyRedirectContext(
                    Context, Options,
                    properties, authorizationEndpoint);
                Options.Provider.ApplyRedirect(redirectContext);
            }

            return(Task.FromResult <object>(null));
        }
コード例 #2
0
 /// <summary>
 /// Called when a Challenge causes a redirect to authorize endpoint in the Auth0 middleware
 /// </summary>
 /// <param name="context">Contains redirect URI and <see cref="AuthenticationProperties"/> of the challenge </param>
 public virtual void ApplyRedirect(Auth0ApplyRedirectContext context)
 {
     OnApplyRedirect(context);
 }