Google使用WebAPI登录

时间:2016-05-02 01:47:04

标签: asp.net-web-api2 owin jwt google-signin openid-connect

我已经在这工作了一个多星期了。我最近使用UseWsFederationAuthentication和UseCookieAuthentication为客户成功设置了Owin,但我正在与另外一个项目的Google的OpenID Connect进行斗争。我已使用Google API信息中心向Google注册了我的应用程序。在浏览器中我可以使用

gapi.auth2.getAuthInstance(); 

获取JWT令牌。在我的Owin ConfigureAuth中,我尝试使用以下内容:

AppBuilder.UseJwtBearerAuthentication(
    new JwtBearerAuthenticationOptions
         {
           AllowedAudiences = new string[] { audience },
           AuthenticationMode = AuthenticationMode.Active,
           IssuerSecurityTokenProviders = new                    
               IIssuerSecurityTokenProvider[]
               {
                   new SymmetricKeyIssuerSecurityTokenProvider(issuer, secret)
               }
          });

我还尝试将TokenValidationParameters设置为基本上不进行任何验证。

new TokenValidationParameters
{
    ValidateActor = false,
    ValidateAudience = false,
    ValidateIssuer = false,                                        
    ValidateIssuerSigningKey = false,
    RequireSignedTokens = false,
    ValidateLifetime = false,
    RequireExpirationTime = false,
}

我还尝试将TokenValidationParameters设置为类似于此处https://github.com/googleplus/gplus-verifytoken-csharp/blob/master/verifytoken.ashx.cs的方式。

我也尝试了很多其他的事情,但没有喜悦。我的要求是让SPA调用带有身份验证令牌的.Net Web API,该令牌将用于验证其ID。应用程序不能依赖cookie,每次都必须处理JWT。

我在我的智慧结束,或者换句话说帮助我,欧比旺克诺比,你是我唯一的希望!

0 个答案:

没有答案