0

I am able to successfully authenticate using my own customAuthenticator.

I need to use a customAuthenticator as the authenticating back end server requires the request header to have the client_id and client_secret.

Something like this.

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

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

however i see there are several utility functions inside the simple-auth-oauth2.js files which the authenticate method uses.

Methods like : absolutizeExpirationTime(response.expires_in); scheduleAccessTokenRefresh(response.expires_in, expiresAt, response.refresh_token);

My question is how do i call these methods inside simple-auth-oauth2 from my customAuthenticator.

I dont want to copy these methods into my customAuthenticator file.....

user3630294
  • 51
  • 1
  • 8

1 Answers1

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);
  }
})
marcoow
  • 4,062
  • 1
  • 14
  • 21
  • But how do i customize the request header..the authenticating backend service expects the request header to have the client_id and client_secret injected to header like this :headers: { "Authorization": "Basic " + btoa(credentials.client_id + ":" + credentials.client_secret) , "API-KEY": window.ENV.api_key }, – user3630294 Jul 18 '14 at 17:11
  • If you want to set a header you have to override `makeRequest` without calling `_super` but instead invoke `Ember.$.ajax` yourself and specify the `headers` option. – marcoow Jul 19 '14 at 11:07