asp.net-core – ASP .Net核心Google身份验证
发布时间:2020-12-16 09:32:56 所属栏目:asp.Net 来源:网络整理
导读:我的.net核心web api应用程序上的google身份验证有问题. 我的用例很简单,从授权标题中的google put token获取bearer token作为“Bearer {token}”并调用我的web api. 但我不能让它发挥作用.我从以下网址获取谷歌令牌后: https://accounts.google.com/o/oaut
我的.net核心web api应用程序上的google身份验证有问题.
我的用例很简单,从授权标题中的google put token获取bearer token作为“Bearer {token}”并调用我的web api. 但我不能让它发挥作用.我从以下网址获取谷歌令牌后: https://accounts.google.com/o/oauth2/v2/auth?scope=email openid& include_granted_scopes = true& state = some_test_state& redirect_uri = http:// localhost:53512& 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(); } 解决方法
这是因为您的身份验证方案是“Google”,但如果您想使用bearer token,则需要将其添加到startup.cs
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { // here's your options }) 并使用此身份验证方案而不是“Google” (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 通过链接按钮单击从一个用户控件到另一个用户控
- 如何在asp.net mvc 3中禁用浏览器缓存?
- asp.net – 使用HtppWebRequest发布表单数据没有效果
- asp.net-mvc – 使用Automapper更新现有的实体POCO
- asp.net-mvc – 带Postgres的ASP.NET MVC; ORM建议?
- asp.net-mvc – ASP.NET MVC的示例企业应用程序?
- asp.net – 在webapi中实现PATCH
- asp.net mvc强类型视图模型与multiselect
- asp.net-mvc – 如何在大型asp.net mvc项目中管理路由
- asp.net – 将webgrid导出为pdf asp mvc razor
推荐文章
站长推荐
- asp.net-mvc – 如何轻松地将Bootstrap应用于已完
- asp.net – 一个cookie文件的最大大小是多少?
- .net – 可以为空的枚举类型的奇怪行为
- asp.net 4.5 webforms模型绑定:支持客户端验证?
- asp.net-mvc – 是否可以绑定资源文件X以发布配置
- 如何在asp.net中编写javascript代码后面使用C#
- asp.net – 在部署时编译ASCX文件而不是首次加载
- asp.net-mvc – ASP.NET MVC应用程序的WatiN最佳
- asp.net-3.5 – 如何在用户控件上获取文本框的值
- asp.net-mvc – 当内容包含PageControl或TabCont
热点阅读