我正在尝试设置一个对许多提供商都有效的身份验证器,因为在后端我正在使用处理整个流程的门卫断言方法。
我已经安装了:
* "ember-cli-simple-auth": "0.8.0-beta.1"
* "ember-cli-simple-auth-oauth2": "^0.8.0-beta.2"
* "ember-cli-simple-auth-torii": "^0.8.0-beta.2"
* "torii": "^0.3.4"
我正在查看Ember-simple-auth、Torii 和 Facebook Oauth2 的这个问题 Workflow,所以我可以这样写:
# templates/login
<a {{action 'oauth2Authenticate' 'facebook-oauth2'}}>Login with facebook</a>
<a {{action 'oauth2Authenticate' 'google-oauth2'}}>Login with google</a>
# controllers/login
actions: {
oauth2Authenticate: function(provider) {
this.get('session').authenticate('authenticator:oauth2', { torii: this.get('torii'), provider: provider });
}
}
# initializers/authentication
import Oauth2Authenticator from '../authenticators/oauth2';
export function initialize(container) {
container.register('authenticator:oauth2', Oauth2Authenticator);
}
export default {
name: 'authentication',
initialize: initialize
};
# authenticators/oauth2
import Ember from 'ember';
import OAuth2 from 'simple-auth-oauth2/authenticators/oauth2';
export default OAuth2.extend({
authenticate: function(options) {
var self = this;
console.log(options.provider);
return new Ember.RSVP.Promise(function(resolve, reject) {
options.torii.open(options.provider).then(function(data) {
var data = {
grant_type: 'assertion',
provider: options.provider,
assertion: data.authorizationCode
};
self.makeRequest(self.serverTokenEndpoint, data).then(function(response) {
Ember.run(function() {
var expiresAt = self.absolutizeExpirationTime(response.expires_in);
self.scheduleAccessTokenRefresh(response.expires_in, expiresAt, response.refresh_token);
resolve(Ember.$.extend(response, { expires_at: expiresAt }));
});
}, function(xhr, status, error) {
Ember.run(function() {
reject(xhr.responseJSON || xhr.responseText);
});
});
}, reject);
});
}
});
# config/environment
ENV['simple-auth'] = {
authorizer: 'simple-auth-authorizer:oauth2-bearer',
crossOriginWhitelist: ['*']
};
ENV['simple-auth-oauth2'] = {
serverTokenEndpoint: ENV.host + '/oauth/token',
refreshAccessTokens: true
};
ENV['torii'] = {
providers: {
'facebook-oauth2': {
apiKey: '631252926924840',
redirectUri: 'http://localhost:4200'
},
'google-oauth2': {
apiKey: '631252926924840',
redirectUri: 'http://localhost:4200'
}
}
};
- POST /oauth/token:我将以下参数传递给服务器:1. grant_type="assertion" 2. provider 3. assertion="3dPartyToken"
我不确定这是否是满足我要求的更好方法,现在我遇到了无法运行 torii 的开放方法的问题,有人知道我做错了什么吗?如果您对此问题有更好的解决方案,将不胜感激。
错误: