这里的任何人都实现了通过Google for Auth0进行社交登录?在与Google验证后,我会遇到令牌(访问和ID)问题。Google社交用Auth0令牌为[Authorized] API调用
这里是我的代码:
var waGoogle = new auth0.WebAuth({
domain: 'testApplication.auth0.com',
clientID: '************',
redirectUri: 'http://localhost:8080/'
})
waGoogle.authorize({
connection: 'google-oauth2',
responseType: 'id_token token'
}, function(err, authResult){
if(err){
console.log('Google Login Error')
console.log(err)
}
});
谷歌画面出现,我登录,我重定向回我的应用程序。从应用程序中,我解析URL以便我可以获取访问和标识令牌。我有
let getParameterByName = (name) => {
var match = RegExp('[#&]' + name + '=([^&]*)').exec(window.location.hash);
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}
var access_token = getParameterByName('access_token')
var id_token = getParameterByName('id_token')
的问题是,没有令牌允许我这样称呼我的API(asp.net网页API)都装修与[授权]属性。它返回一个:
401(未授权)
我知道我的API是否正常工作,如使用正常
用户名,密码,验证
方法在那里我也获得访问令牌,我的API调用只是通过。
从Google获取访问权限和id_token后,我需要执行哪些后续步骤?我是否需要额外拨打Auth0才能获取正确的访问令牌以便能够调用我的Web API?
谢谢。
您是否按照[此处](https://auth0.com/docs/goog-clientid)的说明配置了Google自己的社交连接? –
是的,我做到了。我能够获得令牌(访问和ID),但是我面临的问题是这些令牌未被授权用于我用[授权]为asp.net web api所装饰的API。 – aThink
访问令牌是否获得JWT令牌(包含三个部分的长字符串,由点分隔)。如果是这样,你可以在https://jwt.io中调试它,看看它与使用数据库连接时发出的不同。 –