现在我希望将 Ember-cli 用于我的前端,我需要使用 OpenID Connect 进行身份验证和授权。
以前有没有人做过这样的事情?到目前为止,我找不到任何示例。我遇到了' ember-cli-simple-auth '、' ember-cli-simple-auth-oauth2 '、' ember-cli-simple-auth-token '。
我猜我应该使用“ember-cli-simple-token”?有没有人试过这个?如果是这样,您能指出我的任何示例/阅读资源吗?
更新:(2015 年 7 月 11 日)我一直在研究“ torii ”,尤其是“ ember-cli-torii-azure-provider ”。我可以很好地获得授权代码,但没有 Id_Token (我猜是因为它没有向 Azure AD 询问 Id_Token ),看起来我确实需要考虑编写一个新的 torii 提供程序。根据 Torii 文档,
Torii 将在 Ember 应用程序容器中查找提供程序,因此如果您按常规命名它们(将它们放在 app/torii-providers 目录中),它们将在使用 ember-cli 或 ember 应用程序工具包时自动可用。
这是否意味着,在我的 ember-cli 项目中,我需要创建“torii-providers”文件夹并创建新的提供者?让我们说'torii-azure-openidconnect.js'?
更新:
我正在尝试为 AzureAD OpenID Connect 创建一个自定义 Torii 提供程序。
我收到“错误:提供者的响应缺少这些必需的响应参数:id_token”
这是我的自定义提供程序:
import Ember from 'ember';
import Oauth2 from 'torii/providers/oauth2-code';
import {configurable} from 'torii/configuration';
var computed = Ember.computed;
/**
* This class implements authentication against AzureAD
* using the OAuth2 authorization flow in a popup window.
* @class
*/
export default Oauth2.extend({
name: 'azure-ad-oidc',
baseUrl: computed(function() {
return 'https://login.windows.net/' + this.get('tennantId') + '/oauth2/authorize';
}),
tennantId: configurable('tennantId', 'common'),
// additional url params that this provider requires
requiredUrlParams: ['api-version','response_mode', 'nonce'],
optionalUrlParams: ['scope'],
responseMode: configurable('responseMode', null),
responseParams: computed(function () {
return [ this.get('responseType') ];
}),
state: 'STATE',
apiVersion: '1.0',
nonce : configurable('nonce', null),
responseType: configurable('responseType', 'null'),
redirectUri: configurable('redirectUri', function(){
// A hack that allows redirectUri to be configurable
// but default to the superclass
return this._super();
}),
open: function(){
var name = this.get('name'),
url = this.buildUrl(),
redirectUri = this.get('redirectUri'),
responseParams = this.get('responseParams'),
responseType = this.get('responseType'),
state = this.get('state'),
shouldCheckState = responseParams.indexOf('state') !== -1;
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 new Error("The response from the provider is missing " +
"these required response params: " + missingResponseParams.join(', '));
}
if (shouldCheckState && authData.state !== state) {
throw new Error('The response from the provider has an incorrect ' +
'session state param: should be "' + state + '", ' +
'but is "' + authData.state + '"');
}
return {
authorizationCode: authData[responseType],
provider: name,
redirectUri: redirectUri
};
});
}
});
配置.js
torii: {
sessionServiceName: 'toriiSession',
providers: {
'azure-ad-oidc' :{
tennantId : 'tenant id',
client_id : 'client_id',
redirectUri : 'http://localhost:4200',
nonce : 'my_nonce',
responseMode : 'form_post',
responseType : 'id_token',
scope : 'openid',
apiKey : ''
}
}
},
路线/application.js
import Ember from 'ember';
export default Ember.Route.extend({
actions: {
azureLogin: function() {
this.get('torii').open('azure-ad-oidc').then(function(data) {
var authCode = this.get('toriiSession.authorizationCode');
console.log(authCode);
});
}
}
});
无法锻炼如何解决这个问题..我错过了什么吗?