因此,我使用OAuth 2.0扩展来设置ember-simple-auth。问题是每当我尝试登录并查看作为表单数据发送的内容时,它只发送grant_type和password参数。但是,password参数始终为空,有时甚至不显示。username参数总是丢失,到目前为止我还没有看到它。
这是我的login.hbs代码(顺便说一句,我使用的是ember-cli)
<form {{action 'authenticate' on='submit'}}>
<label for="identification">Login</label>
{{input class="form-control" id='identification' placeholder='Enter Login' value=identification}}
<label for="password">Password</label>
{{input class="form-control" id='password' placeholder='Enter Password' type='password' value=password}}
<button type="submit">Login</button>
</form>我用controllers编写的login.js代码
import Ember from 'ember';
import LoginControllerMixin from 'simple-auth/mixins/login-controller-mixin';
export default Ember.Controller.extend(LoginControllerMixin, {
authenticator: 'simple-auth-authenticator:oauth2-password-grant'
});我用controllers编写的application.js代码
// app/routes/application.js
import Ember from 'ember';
import ApplicationRouteMixin from 'simple-auth/mixins/application-route-mixin';
export default Ember.Route.extend(ApplicationRouteMixin);在config/environment.js文件中
if (environment === 'development') {
…
ENV['simple-auth-oauth2'] = {
serverTokenEndpoint: '/api/v1/oauth/token'
}
…
}It's making the call to the right url after this change
在我的初始化器文件夹中
// app/initializers/simple-auth-config.js
export default {
name: 'simple-auth-config',
before: 'simple-auth',
initialize: function() {
window.ENV = FrontENV;
}
};很容易注意到,这些代码的大部分都是从simplelabs教程中复制过来的,并进行了一些定制。然而,我不明白为什么参数没有被正确发送。任何帮助都将不胜感激!
发布于 2015-01-22 03:22:33
缺少的参数是client_id和client_secret。Ember-Simple-Auth OAuth 2.0不包括这些,因为它们在ember应用程序中使用时不是秘密的。您需要创建一个这样的自定义身份验证器,以包含这两个参数:
//app/authenticators/mine.js
import Authenticator from 'simple-auth-oauth2/authenticators/oauth2';
export default Authenticator.extend({
makeRequest: function(url, data) {
data.client_id = '…';
data.client_secret = '…';
return this._super(url, data);
}
});您可以像使用OAuth 2.0验证器一样使用它,只需将simple-auth-authenticator:oauth2-password-grant替换为authenticator:mine即可。
下面是一个工作示例的其余文件。
//app/controllers/login.js
import Ember from 'ember';
import LoginControllerMixin from 'simple-auth/mixins/login-controller-mixin';
export default Ember.Controller.extend(LoginControllerMixin, {
authenticator: 'authenticator:mine'
});//app/routes/application.js
import Ember from 'ember';
import ApplicationRouteMixin from 'simple-auth/mixins/application-route-mixin';
export default Ember.Route.extend(
ApplicationRouteMixin
);//app/routes/index.js
import Ember from 'ember';
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
export default Ember.Route.extend(
AuthenticatedRouteMixin
);//app/routes/login.js
import Ember from 'ember';
import UnauthenticatedRouteMixin from 'simple-auth/mixins/unauthenticated-route-mixin';
export default Ember.Route.extend(
UnauthenticatedRouteMixin
);<!-- app/templates/application.hbs -->
{{#if session.isAuthenticated}}
<h2 id="title">Welcome to Ember.js</h2>
<a {{ action 'invalidateSession' }}>Logout</a>
{{/if}}
{{outlet}}<!-- app/templates/index.hbs -->
<p>Private page</p><!-- app/templates/login.hbs -->
<form {{action 'authenticate' on='submit'}}>
<label for="identification">Login</label>
{{input value=identification placeholder='Enter Login'}}
<label for="password">Password</label>
{{input value=password placeholder='Enter Password' type='password'}}
<button type="submit">Login</button>
</form>//config/environment.js
(…)
ENV['simple-auth'] = {
authorizer: 'simple-auth-authorizer:oauth2-bearer'
}
ENV['simple-auth-oauth2'] = {
serverTokenEndpoint: '/api/v1/oauth/token'
}
(…)这个答案是从上述question on the Ember Simple Auth issue tracker上的评论中得出的。
https://stackoverflow.com/questions/24699086
复制相似问题