0

我能够使用我自己的 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 文件中.....

4

1 回答 1

0

You can simple define a custom authenticator that extends the OAuth 2.0 authenticator. The only method you have to override is makeRequest, e.g.:

var CustomAuthenticator = Authenticators.OAuth2.extend({
  makeRequest: function(url, data) {
    data.client_id     = …;
    data.client_secret = …;
    return this._super(url, data);
  }
})
于 2014-07-18T16:59:08.283 回答