[英]ember.js - getting access token using simple auth/torii
I am using ember.js, simple auth, and torii for oauth with Spotify. 我正在使用Spoter将ember.js,简单身份验证和torii用于oauth。 I can currently log in and log out just fine, and looking at resources I can see I am getting an access token from Spotify.
我目前可以正常登录和注销,然后查看资源,可以看到我正在从Spotify获取访问令牌。
When I log session.data
as the simple auth docs say, I am getting an Object with all my data in it, including my access token. 当我按照简单的身份验证文档所述记录
session.data
,我正在获取一个包含所有数据(包括访问令牌)的对象。 However, I can't seem to pull out that access token. 但是,我似乎无法拉出该访问令牌。 I have tried
session.data.authenticated
to just access the next level of the object, but that returns an empty object. 我尝试了
session.data.authenticated
来访问对象的下一个级别,但是返回一个空对象。 If I try to get to the access_token
, I get undefined
calling session.data.access_token
. 如果我尝试访问
access_token
, access_token
得到undefined
调用session.data.access_token
。
app/controllers/application.js
: app/controllers/application.js
:
import Ember from 'ember'
export default Ember.Controller.extend({
session: Ember.inject.service('session'),
actions: {
login () {
this.get('session').authenticate('authenticator:torii', 'spotify-oauth2-bearer')
console.log(this.get('session.data'))
},
logout () { this.get('session').invalidate() }
}
})
app/authenticators/torii.js
: app/authenticators/torii.js
:
import Ember from 'ember'
import ToriiAuthenticator from 'ember-simple-auth/authenticators/torii'
export default ToriiAuthenticator.extend({ torii: Ember.inject.service() })
How can I get to my access token? 如何获得访问令牌?
session.data.authenticated
is undefined at the time you are logging to console. 在登录控制台时,
session.data.authenticated
未定义。
this.get('session').authenticate(...)
is async and returns a promise. this.get('session').authenticate(...)
是异步的,并返回一个Promise。 By logging to the console right after the call, the authentication might not have completed yet. 通过在呼叫后立即登录到控制台,验证可能尚未完成。
Try doing: 尝试做:
this.get('session').authenticate(...).then(() => {
console.log(this.get('session.data.authenticated'));
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.