Ember-Simple-Auth with Torii访问用户信息 [英] Ember-Simple-Auth with Torii access user info
问题描述
我一整周都在工作,让身份验证工作。我已经得到了它的工作与
I've been working all week to get authentication working. I have gotten it working with
- Ember-CLI
- Ember-Simple-Auth
- Torii
- google-oauth2提供者
然而,我已经证明不能从谷歌获取用户信息。我已经尝试创建一个torii适配器,如他们的文档中所述,但似乎没有被称为
However I have proven unsuccessful in getting the users information from google. I have tried creating a torii-adapter as stated in their documentation but it doesn't appear to be called
// app/torii-adapters/application.js export default Ember.Object.extend({ open: function(authorization){ console.log('authorization from adapter', authorization); } });
我已经用尽了我的google-foo,并要求您的帮助。这是一个伟大的图书馆组合的授权,但文件缺乏这种情况,当想到我将一定会贡献回来。
I've exhausted my google-foo and am asking for your assistance. This is a great library combination for authorization however the documentation is lacking for this case, and when figured out I will be sure to contribute back.
谢谢
推荐答案
我遇到的问题是Torii的默认google-oauth2提供程序不会为您访问此信息,它也使用代码工作流而不是google + API需要的令牌工作流程
The problem I was encountering is Torii's default google-oauth2 provider doesn't access this info for you, also it uses the code workflow instead of the token workflow which is needed for the google+ API
为了解决这个问题,我写了一个使用jQuery的GET请求给G + API的定制提供者,然后我返回userName和用户电子邮件在会话的内容下访问它。
To fix this I wrote a custom provider that uses a jquery GET request to the G+ API, I then return the userName and userEmail to access it in the session under content.
我写了一个完整的教程,详细说明了使用google开始完成一个ember应用程序的开始 here
I wrote a full tutorial detailing authorizing an ember app using google start to finish here
//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;
这篇关于Ember-Simple-Auth with Torii访问用户信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!