我的.net核心web api应用程序上的google身份验证存在问题。 我的用例很简单,从授权标题中的google put token获取bearer token作为" Bearer {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();
}
答案 0 :(得分:0)
这是因为您的身份验证方案是“ Google”,但是如果要使用承载令牌,则需要将其添加到startup.cs
Dim shell As Shell32.Shell = New Shell32.Shell()
shell.ToggleDesktop()
并使用此身份验证方案代替“ Google”