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 extra = challenge.Properties;
                if (string.IsNullOrEmpty(extra.RedirectUri))
                {
                    extra.RedirectUri = currentUri;
                }

                // OAuth2 10.12 CSRF
                GenerateCorrelationId(Options.CookieManager, extra);

                // OAuth2 3.3 space separated
                string scope = string.Join(" ", Options.Scope);
                // LiveID requires a scope string, so if the user didn't set one we go for the least possible.
                if (string.IsNullOrWhiteSpace(scope))
                {
                    scope = "snsapi_login";
                }

                //https://open.weixin.qq.com/connect/qrconnect?appid=wxc03b938685ab0b74&redirect_uri=http://jiayuan.sunnyroofs.cn&response_type=code&scope=snsapi_login&state=STATE#wechat_redirect

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

                string authorizationEndpoint =
                    Options.AuthorizationEndpoint +
                    "?appid=" + Uri.EscapeDataString(Options.AppId) +
                    "&scope=" + Uri.EscapeDataString(scope) +
                    "&response_type=code" +
                    "&redirect_uri=" + Uri.EscapeDataString(redirectUri)
                    + "&state=" + Uri.EscapeDataString(state);

                var redirectContext = new WeChatAccountApplyRedirectContext(
                    Context, Options,
                    extra, authorizationEndpoint);
                Options.Provider.ApplyRedirect(redirectContext);
            }

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