按照文档中的说明,我设置了Facebook身份验证,如下所示:
"dependencies": {
//blah blah snip
"Microsoft.AspNetCore.Authentication.Facebook": "1.0.0-rc2-final"
},
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
//blah blah snip
app.UseIdentity();
// Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715
app.UseFacebookAuthentication(new FacebookOptions()
{
AppId = Configuration["Authentication:Facebook:AppId"],
AppSecret = Configuration["Authentication:Facebook:AppSecret"],
});
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}在从Facebook上获取AppId和AppSecret并使用SecretManager存储它们之后,我启动了它们,从而成功地登录了Facebook,并且非常高兴。
在成功的鼓舞下,我试图按照同样的思路建立谷歌认证。
"dependencies": {
//blah blah snip
"Microsoft.AspNetCore.Authentication.Facebook": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Authentication.Google": "1.0.0-rc2-final"
},
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
//blah blah snip
app.UseIdentity();
// Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715
app.UseFacebookAuthentication(new FacebookOptions()
{
AppId = Configuration["Authentication:Facebook:AppId"],
AppSecret = Configuration["Authentication:Facebook:AppSecret"],
});
app.UseGoogleAuthentication(new GoogleOptions()
{
ClientId = Configuration["Authentication:Google:ClientId"],
ClientSecret = Configuration["Authentication:Google:ClientSecret"],
});
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}它几乎可以工作,但是The redirect URI in the request, https://localhost:44391/signin-google, does not match the ones authorized for the OAuth client.
一项研究表明,重定向URL是由CallbackPath对象的GoogleOptions属性的值提供的,它默认为“signin”。我没有登录-谷歌路径,CallbackPath = "/"在应用初始化过程中会产生一个未处理的远程故障(不管是什么),所以我删除了它,用谷歌更新了应用程序的详细信息,允许https://localhost:44391/signin-google作为重定向路径。
这让我被提示授予应用程序“有离线访问”,所以我做到了。
但是现在我得到了403个像state=8b968ac03c755e48f2c1479fea9c02b9ccaa292a..4748&prompt=none#这样的URL
我试过像这样设置范围
var go = new GoogleOptions()
{
ClientId = Configuration["Authentication:Google:ClientId"],
ClientSecret = Configuration["Authentication:Google:ClientSecret"],
};
go.Scope.Add("email");
go.Scope.Add("profile");
app.UseGoogleAuthentication(go);有趣的是,默认范围是"openid“。添加"email“和"profile”作用域并没有在授予请求中产生任何差异。添加无效的作用域会产生一个错误,这意味着这些都是有效的识别作用域。
使用Google+控制台为应用程序启用Google+ API可以解决403禁止的错误,但出于逃避我的原因,我们仍然被提示授予离线访问权限。
GoogleOptions对象具有默认为null的属性AccessType。将其设置为“联机”似乎没有什么不同。
问题
提示我授予脱机访问权限。是什么让服务器认为我想要离线访问?需要设置什么来防止这种情况发生?在AccessType = "online"对象初始化器中设置GoogleOptions
var go = new GoogleOptions()
{
AccessType = "online",
ClientId = Configuration["Authentication:Google:ClientId"],
ClientSecret = Configuration["Authentication:Google:ClientSecret"],
};似乎没有任何效果。这是正确的价值吗?
发布于 2016-06-10 06:52:33
脱机访问是一组不同范围的默认消息,电子邮件和配置文件是其中的两个。除了停止请求配置文件和电子邮件作用域之外,无法更改消息。
AccessType (在线的,离线的)并不是你想的那样。脱机访问将返回一个刷新令牌,以便以后访问他们的数据。在线访问意味着您只会访问他们的数据时,他们在那里,你不需要一个刷新令牌。
https://stackoverflow.com/questions/37691868
复制相似问题