Asp.net core ASP.Net核心Google身份验证
我的.net核心web api应用程序上的google身份验证有问题。 我的用例很简单,从GooglePutToken以“bearer{token}”的形式从授权头中获取承载令牌,并调用我的web api 但我不能让它工作。在我从google获得以下url上的令牌后:Asp.net core ASP.Net核心Google身份验证,asp.net-core,oauth-2.0,.net-core,Asp.net Core,Oauth 2.0,.net Core,我的.net核心web api应用程序上的google身份验证有问题。 我的用例很简单,从GooglePutToken以“bearer{token}”的形式从授权头中获取承载令牌,并调用我的web api 但我不能让它工作。在我从google获得以下url上的令牌后: https://accounts.google.com/o/oauth2/v2/auth?scope=email%20openid&include_granted_scopes=true&state=some_test_state
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授权
这是我的创业课程:
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();
}
公共静态IConfigurationRoot配置{get;private set;}
//此方法由运行时调用。使用此方法向容器中添加服务
public void配置服务(IServiceCollection服务)
{
services.AddMvc();
//从配置对象中拉入任何SDK配置
services.AddDefaultAWSOptions(Configuration.GetAWSOptions());
//将S3添加到ASP.NET核心依赖项注入框架。
services.AddAWSService();
IocConfig.Configure(服务);
}
//此方法由运行时调用。使用此方法配置HTTP请求管道
公共void配置(IApplicationBuilder应用程序、IHostingEnvironment环境、iLogger工厂)
{
loggerFactory.AddLambdaLogger(配置.GetLambdaLoggerOptions());
var googleOptions=新的googleOptions
{
AuthenticationScheme=“谷歌”,
ClientId=“ClientId”,
ClientSecret=“cs”,
signScheme=“谷歌”
};
app.UseGoogleAuthentication(谷歌选项);
app.UseDeveloperExceptionPage();
app.UseMvc();
}
这是因为您的身份验证方案是“Google”,但如果您想使用承载令牌,则需要将其添加到startup.cs
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
// here's your options
})
并使用此身份验证方案而不是“谷歌”您找到答案了吗?我自己也在挣扎。是的,我自己写了中间件。