【问题标题】:how to use ember-simple-oauth2 authenticate from imy CustomAuthenticator如何使用来自 imy CustomAuthenticator 的 ember-simple-oauth2 进行身份验证
【发布时间】:2014-07-18 14:38:53
【问题描述】:

我能够使用我自己的 customAuthenticator 成功进行身份验证。

我需要使用 customAuthenticator,因为身份验证后端服务器需要 请求标头具有 client_id 和 client_secret。

类似的东西。

  headers: {
           "Authorization": "Basic " + btoa(credentials.client_id + ":" +  
            credentials.client_secret) ,

           "API-KEY": window.ENV.api_key
           },

但是我看到 simple-auth-oauth2.js 文件中有几个实用程序函数 验证方法使用哪个。

方法如下: absolutizeExpirationTime(response.expires_in); scheduleAccessTokenRefresh(response.expires_in, expiresAt, response.refresh_token);

我的问题是如何从我的 customAuthenticator 调用 simple-auth-oauth2 中的这些方法。

我不想将这些方法复制到我的 customAuthenticator 文件中.....

【问题讨论】:

    标签: ember.js ember-simple-auth


    【解决方案1】:

    您可以简单地定义一个扩展 OAuth 2.0 身份验证器的自定义身份验证器。您必须覆盖的唯一方法是makeRequest,例如:

    var CustomAuthenticator = Authenticators.OAuth2.extend({
      makeRequest: function(url, data) {
        data.client_id     = …;
        data.client_secret = …;
        return this._super(url, data);
      }
    })
    

    【讨论】:

    • 但是我如何自定义请求标头..身份验证后端服务期望请求标头将 client_id 和 client_secret 注入到标头中,如下所示:headers: { "Authorization": "Basic" + btoa (credentials.client_id + ":" + credentials.client_secret) , "API-KEY": window.ENV.api_key },
    • 如果你想设置一个标题,你必须覆盖makeRequest而不调用_super,而是自己调用Ember.$.ajax并指定headers选项。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-29
    • 2017-07-15
    • 1970-01-01
    • 2020-02-19
    • 1970-01-01
    • 2018-09-24
    • 1970-01-01
    相关资源
    最近更新 更多