Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
是否可以使用标准Owin在应用程序中与Google、Yahoo和Twitter进行身份验证?_Twitter_Owin_Yahoo - Fatal编程技术网

是否可以使用标准Owin在应用程序中与Google、Yahoo和Twitter进行身份验证?

是否可以使用标准Owin在应用程序中与Google、Yahoo和Twitter进行身份验证?,twitter,owin,yahoo,Twitter,Owin,Yahoo,是否有人拥有与谷歌、雅虎和推特合作的标准Owin? 我遇到了一个奇怪的问题,如果我使用谷歌,然后添加雅虎或Twitter,提供商在登录后会得到一个空白屏幕 这是我正在使用的代码: #region Yahoo var yahooAuthOptions = new YahooAuthenticationOptions(); // Same issue if using: Owin.Security.Providers.Yahoo.YahooAuthenticationOptions

是否有人拥有与谷歌、雅虎和推特合作的标准Owin?

我遇到了一个奇怪的问题,如果我使用谷歌,然后添加雅虎或Twitter,提供商在登录后会得到一个空白屏幕

这是我正在使用的代码:

    #region Yahoo

    var yahooAuthOptions = new YahooAuthenticationOptions(); // Same issue if using: Owin.Security.Providers.Yahoo.YahooAuthenticationOptions();
    yahooAuthOptions.ConsumerKey = externalProviderManager.YahooAuthConsumerKey;
    yahooAuthOptions.ConsumerSecret = externalProviderManager.YahooAuthConsumerSecret;
    yahooAuthOptions.CallbackPath = new PathString("/signin-external"); // Note: by default yahoo is looking for a route named "signin-yahoo"

    yahooAuthOptions.Provider = new YahooAuthenticationProvider()
    {
        OnAuthenticated = (context) =>
        {
            foreach (var claim in context.User)
            {
                var claimType = string.Format("urn:yahoo:{0}", claim.Key);
                var claimValue = claim.Value.ToString();
                if (!context.Identity.HasClaim(claimType, claimValue))
                    context.Identity.AddClaim(new System.Security.Claims.Claim(claimType, claimValue, "XmlSchemaString", "Yahoo"));
            }

            return Task.FromResult(0);
        }
    };
    app.UseYahooAuthentication(yahooAuthOptions);

    #endregion Yahoo

    #region Google

    var googleAuthOptions = new GoogleOAuth2AuthenticationOptions();
    googleAuthOptions.ClientId = externalProviderManager.GoogleAuthClientId;
    googleAuthOptions.ClientSecret = externalProviderManager.GoogleAuthClientSecret;
    googleAuthOptions.CallbackPath = new PathString("/signin-external");

    // googleAuthOptions.Scope.Add("https://www.googleapis.com/auth/plus.me"); // Know who you are on Google
    googleAuthOptions.Scope.Add("https://www.googleapis.com/auth/plus.login"); // Know your basic profile info and list of people in your circles.
    googleAuthOptions.Scope.Add("https://www.googleapis.com/auth/userinfo.email"); // View your email address
    googleAuthOptions.Scope.Add("https://www.googleapis.com/auth/userinfo.profile"); // View your basic profile info

    googleAuthOptions.Provider = new GoogleOAuth2AuthenticationProvider
    {
        OnAuthenticated = (context) =>
        {
            context.Identity.AddClaim(new System.Security.Claims.Claim("GoogleAccessToken", context.AccessToken));

            var expiryDuration = context.ExpiresIn ?? new TimeSpan();
            context.Identity.AddClaim(new Claim("urn:google:expires_in", DateTime.UtcNow.Add(expiryDuration).ToString(CultureInfo.InvariantCulture)));

            if (context.Email != null) context.Identity.AddClaim(new Claim("urn:google:email", context.Email));
            if (context.Id != null) context.Identity.AddClaim(new Claim("urn:google:id", context.Id));
            if (context.GivenName != null) context.Identity.AddClaim(new Claim("urn:google:given_name", context.GivenName));
            if (context.FamilyName != null) context.Identity.AddClaim(new Claim("urn:google:family_name", context.FamilyName));
            if (context.Name != null) context.Identity.AddClaim(new Claim("urn:google:name", context.Name));
            if (context.Profile != null) context.Identity.AddClaim(new Claim("urn:google:profile", context.Profile));

            // Note: for the birthday value (yyyy/mm/dd) - make sure Google Plus profile allows sharing birthday with public

            // Add all other available claims
            foreach (var claim in context.User)
            {
                var claimType = string.Format("urn:google:{0}", claim.Key);
                var claimValue = claim.Value.ToString();
                if (!context.Identity.HasClaim(claimType, claimValue))
                    context.Identity.AddClaim(new System.Security.Claims.Claim(claimType, claimValue, "XmlSchemaString", "Google"));
            }

            return Task.FromResult(0);
        }
    };
    app.UseGoogleAuthentication(googleAuthOptions);

    #endregion Google

    #region Facebook

    var facebookAuthOptions = new FacebookAuthenticationOptions();
    facebookAuthOptions.AppId = externalProviderManager.FacebookAuthAppId;
    facebookAuthOptions.AppSecret = externalProviderManager.FacebookAuthAppSecret;
    facebookAuthOptions.SendAppSecretProof = true;

    // public_profile (Default) includes: id,name,first_name,last_name,age_range,link,gender,locale,timezone,updated_time,verified
    facebookAuthOptions.Scope.Add("public_profile");
    facebookAuthOptions.Scope.Add("email");
    facebookAuthOptions.Scope.Add("user_birthday");
    facebookAuthOptions.Scope.Add("user_location"); // current city through the location field on the User object

    facebookAuthOptions.Provider = new FacebookAuthenticationProvider()
    {
        OnAuthenticated = (context) =>
        {
            // http://stackoverflow.com/questions/7999934/facebook-c-sharp-sdk-problems-getting-user-email/8013211#8013211
            // http://blogs.msdn.com/b/webdev/archive/2013/10/16/get-more-information-from-social-providers-used-in-the-vs-2013-project-templates.aspx
            // Get the access token from FB and store it in the database and use FacebookC# SDK to get more information about the user
            context.Identity.AddClaim(new System.Security.Claims.Claim("FacebookAccessToken", context.AccessToken));

            var expiryDuration = context.ExpiresIn ?? new TimeSpan();
            context.Identity.AddClaim(new Claim("urn:facebook:expires_in", DateTime.UtcNow.Add(expiryDuration).ToString(CultureInfo.InvariantCulture)));

            // Add all other available claims
            foreach (var claim in context.User)
            {
                var claimType = string.Format("urn:facebook:{0}", claim.Key);
                var claimValue = claim.Value.ToString();
                if (!context.Identity.HasClaim(claimType, claimValue))
                    context.Identity.AddClaim(new System.Security.Claims.Claim(claimType, claimValue, "XmlSchemaString", "Facebook"));
            }

            return Task.FromResult(0);
        }
    };
    app.UseFacebookAuthentication(facebookAuthOptions);

    #endregion Facebook

这是一个很难解决的问题

我试图为我的所有外部提供者使用一个全面回调URI

一旦我在RouteConfig.cs中分别为每个提供者创建了一个条目,一切都像一个符咒一样工作


当然,还要更新提供商应用程序界面上的所有回调URI…

这是一个很难解决的问题

我试图为我的所有外部提供者使用一个全面回调URI

一旦我在RouteConfig.cs中分别为每个提供者创建了一个条目,一切都像一个符咒一样工作

当然,还要更新提供者应用程序接口上的所有回调URI