我的自定义授权程序文件看起来像这样但不起作用:
import Ember from 'ember';
import Base from 'ember-simple-auth/authorizers/base';
export default Base.extend({
authorize: function(jqXHR, requestOptions) {
var accessToken = this.get('session.content.secure.token');
if (this.get('session.isAuthenticated') && !Ember.isEmpty(accessToken)) {
jqXHR.setRequestHeader('Authorization', 'Bearer ' + accessToken);
}
}
});
在审核了这篇文章之后:http://simplabs.com/blog/2015/11/27/updating-to-ember-simple-auth-1.0.html我仍然不清楚,我应该在这里打电话给授权人吗?会话商店怎么样?请有人可以向我澄清这一点,我收到错误授权者未定义:
我的ajax电话看起来像这样:
import Ember from 'ember';
export default Ember.Component.extend({
session: Ember.inject.service(),
gotQuote: false,
quote: "",
actions: {
getQuote: function() {
var that = this;
this.get('session').authorize('authorizer:cusmtom', (headerName, headerValue) => {
const headers = {};
headers[headerName] = headerValue;
Ember.$.ajax({
type: 'GET',
url: 'http://www.example/api/quotes',
headers: headers,
success: function(response) {
that.setProperties({
quote: response.quoteText,
gotQuote: true
});
},
error: function(xhr) {
alert('Request Status: ' + xhr.status + ' Status Text: ' + xhr.statusText + ' ' + xhr.responseText);
}
});
});
}
}
});