【问题标题】:Ember oauth2 Authentication issuesEmber oauth2 身份验证问题
【发布时间】:2014-08-16 09:28:31
【问题描述】:

获取一个 [error="unauthorized", error_description="完整身份验证 需要访问此资源”] 尝试将 ember 应用程序连接到 oauth2 身份验证服务时。 任何建议将不胜感激。我花了几天时间试图解决这个问题,但无济于事。

这是 app.js 中的代码


         Ember.Application.initializer({
      name: 'authentication',
      initialize: function(container, application) {
         Ember.SimpleAuth.Authenticators.OAuth2.reopen({
                     makeRequest: function(credentials) {
                         credentials.client_id= 'rsweb-client';
                         credentials.client_secret= '123456';
                         credentials.scope='read';
return Ember.$.ajax({ type: "POST", url: 'http://127.0.0.1:8080/api/oauth/token', async: false, data:credentials,
success: function (data, textStatus, xhr){ Ember.run(function(){ resolve({username: data['pl-usr-nickname']}); }); }, error: function (xhr, status, error){ Ember.run(function(){ console.log(xhr.responseText); }); } }); } });
Ember.SimpleAuth.setup(container, application, { // @todo at version 0.1.2 of Ember-simple-auth, add container crossOriginWhitelist: ['http://127.0.0.1:8080'], // @todo remove when live // store: Ember.SimpleAuth.Stores.LocalStorage, authenticationRoute: 'login' }); } }); Here is the # The OAuth-secured REST Endpoint This uses the simple OAuth Resource Owner Password flow. Here is an example of how to acquired an access_token, and then use that access_token to update an application. ``` curl --noproxy localhost -X POST -vu rsweb-client:123456 http://127.0.0.1:8080/api/oauth/token -H "Accept: application/json" -d "password=password&username=user&grant_type=password&scope=read&client_secret=123456&client_id=rsweb-client"

This returns an token when i access from the command line tool. But not from the ember app.

Here is the request payload:

Content-Type application/x-www-form-urlencoded; charset=UTF-8 Accept */* Parameters application/x-www-form-urlencoded client_id rsweb-client client_secret 123456 grant_type password password password scope read username user

【问题讨论】:

    标签: ember.js oauth oauth-2.0


    【解决方案1】:

    看起来您的身份验证服务器期望 client_id 和 client_secret 作为 HTTP 基本身份验证凭据,而您的身份验证器在有效负载中发送它们。您必须按照定义在 makeRequest 方法中添加 Authorization 标头,例如这里:https://www.rfc-editor.org/rfc/rfc2617 这将是“rsweb-client:123456”的 base64 编码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-22
      • 2016-04-27
      相关资源
      最近更新 更多