OAuth 2配置

时间:2015-03-20 16:50:29

标签: c# asp.net-web-api oauth-2.0 google-oauth

您尝试使用OAuth2 redirect_uri_mismatch登录时收到错误。服务器和客户端代码工作正常,但我必须在谷歌中配置一个新项目并为Web应用程序获取新的谷歌客户端ID,现在不工作。

这就是我所拥有的:

Mvc.WebApi.AuthServer - >它启用了OAuth2和google身份验证http://localhost:50668/

Mvc.WebApi.Client->我必须使用谷歌从客户端http://localhost:12731/

登录我的authServer

在服务器的Startup.cs中:

googleAuthOptions = new GoogleOAuth2AuthenticationOptions()
        {
            ClientId = "515569638546-02hgtoe06v2k633nuk6220vdo7tqqmgg.apps.googleusercontent.com",
            ClientSecret = "FF8p4bsSIG-KT0AS8Ts-HfEb", //not real
            Provider = new GoogleAuthProvider()
        };
        googleAuthOptions.Scope.Add("email");
        app.UseGoogleAuthentication(googleAuthOptions);

在客户的.js中:

$scope.authExternalProvider = function (provider) {

    var redirectUri = http://localhost:12731/authcomplete.html;

    var externalProviderUrl = "http://localhost:50668/" + "api/Account/ExternalLogin?provider=" + provider
                                                                + "&response_type=token"
                                                                + "&scope=email"
                                                                + "&redirect_uri=" + redirectUri;
    window.$windowScope = $scope;

    var oauthWindow = window.open(externalProviderUrl, "Authenticate Account", "location=0,status=0,width=1000,height=750");
};

以上代码用于工作,我在下面创建:

Google Developer Console,凭据配置

我登录时遇到此错误: 那是一个错误。 错误:redirect_uri_mismatch 请求中的重定向URI:http://localhost:50668/signin-google与注册的重定向URI不匹配。

0 个答案:

没有答案
相关问题