我花了一周的时间来做认证工作。我已经让它和
然而,事实证明,我无法从谷歌获得用户信息。我尝试过创建一个torii适配器,如他们的文档中所述,但是它似乎没有被调用。
// app/torii-adapters/application.js
export default Ember.Object.extend({
open: function(authorization){
console.log('authorization from adapter', authorization);
}
});我已经用尽了我的google-foo,我请求你的帮助。这是一个很好的授权库组合,但是在这种情况下缺乏文档,并且当我知道之后,我肯定会贡献回来的。
谢谢
发布于 2014-12-20 20:03:37
我遇到的问题是Torii的默认GoogleOAuth2提供者不为您访问这些信息,它还使用代码工作流而不是google+ API所需的令牌工作流。
为了解决这个问题,我编写了一个自定义提供程序,它使用jquery请求访问G+ API,然后返回userName和userEmail,以便在会话中通过内容访问它。
我编写了一个完整的教程,详细说明如何授权使用google完成这里的ember应用程序。
//app/torii-providers/google-token.js
import {configurable} from 'torii/configuration';
import Oauth2Bearer from 'torii/providers/oauth2-bearer';
var GoogleToken = Oauth2Bearer.extend({
name: 'google-token',
baseUrl: 'https://accounts.google.com/o/oauth2/auth',
// additional params that this provider requires
requiredUrlParams: ['state'],
optionalUrlParams: ['scope', 'request_visible_actions', 'access_type'],
requestVisibleActions: configurable('requestVisibleActions', ''),
accessType: configurable('accessType', ''),
responseParams: ['token'],
scope: configurable('scope', 'email'),
state: configurable('state', 'STATE'),
redirectUri: configurable('redirectUri',
'http://localhost:8000/oauth2callback'),
open: function(){
var name = this.get('name'),
url = this.buildUrl(),
redirectUri = this.get('redirectUri'),
responseParams = this.get('responseParams');
var client_id = this.get('client_id');
return this.get('popup').open(url, responseParams).then(function(authData){
var missingResponseParams = [];
responseParams.forEach(function(param){
if (authData[param] === undefined) {
missingResponseParams.push(param);
}
});
if (missingResponseParams.length){
throw "The response from the provider is missing " +
"these required response params: " + responseParams.join(', ');
}
return $.get("https://www.googleapis.com/plus/v1/people/me", {access_token: authData.token}).then(function(user){
return {
userName: user.displayName,
userEmail: user.emails[0].value,
provider: name,
redirectUri: redirectUri
};
});
});
}
});
export default GoogleToken;https://stackoverflow.com/questions/27553593
复制相似问题