【发布时间】:2015-08-01 00:41:57
【问题描述】:
现在我希望将 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 : ''
}
}
},
routes/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);
});
}
}
});
无法解决如何解决这个问题..我错过了什么吗?
【问题讨论】:
-
您可能需要实现自定义身份验证器。 Ember Simple Auth 是一个高级库,它实现了一个会话和一个接口来验证它。要使用 OpenID,您必须实现自定义身份验证器 - 请参阅此示例了解如何开始:github.com/simplabs/ember-simple-auth/blob/master/examples/…。另请查看 API 文档:ember-simple-auth.com/ember-simple-auth-api-docs.html
-
Thx marcoow,当我更新我的问题时,我正在考虑实施一个自定义 torii 提供程序..
-
我将感兴趣地关注这个主题的发展,因为我们将把我们的身份验证堆栈切换到 OpenID Connect,并且拥有一个 Ember 身份验证客户端会很棒。我见过的最接近的东西是 torii repo 上的这个 PR:github.com/Vestorly/torii/pull/216(但看起来它已经停滞了)。
标签: ember-cli azure-active-directory openid-connect torii