【发布时间】:2017-06-15 12:02:45
【问题描述】:
我的 .net 核心 Web api 应用程序上的 google 身份验证存在问题。 我的用例很简单,从谷歌获取不记名令牌,将授权标头中的令牌作为“不记名{token}”并调用我的网络 api。
但我不能让它工作。在我通过以下网址从谷歌获得令牌后:
https://accounts.google.com/o/oauth2/v2/auth?scope=email%20openid&include_granted_scopes=true&state=some_test_state&redirect_uri=http%3A%2F%2Flocalhost%3A53512&response_type=token&client_id={someClientID}
我将使用标题调用我的 api:
Authorization: Bearer {TokenValue}
但是每次我得到 401 Unauthorized.
这是我的 Startup 课程:
public static IConfigurationRoot Configuration { get; private set; }
// This method gets called by the runtime. Use this method to add services to the container
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
// Pull in any SDK configuration from Configuration object
services.AddDefaultAWSOptions(Configuration.GetAWSOptions());
// Add S3 to the ASP.NET Core dependency injection framework.
services.AddAWSService<Amazon.S3.IAmazonS3>();
IocConfig.Configure(services);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddLambdaLogger(Configuration.GetLambdaLoggerOptions());
var googleOptions = new GoogleOptions
{
AuthenticationScheme = "Google",
ClientId = "clientid",
ClientSecret = "cs",
SignInScheme = "Google"
};
app.UseGoogleAuthentication(googleOptions);
app.UseDeveloperExceptionPage();
app.UseMvc();
}
【问题讨论】:
-
大家找到答案了吗?我自己也在挣扎。
-
是的,我自己写了中间件。
标签: asp.net-core oauth-2.0 .net-core