A
A
Alexey Aristov2016-06-24 19:16:13
JavaScript
Alexey Aristov, 2016-06-24 19:16:13

Ember Simple Auth Token: how to add information to header of request sent by authenticator:jwt?

Installed the authenticator:

ember install ember-simple-auth
ember install ember-simple-auth-token

and try to use it:
export default Ember.Controller.extend({
  session: Ember.inject.service(),
  actions: {
    login() {
      var credentials = this.getProperties('identification', 'password'),
        authenticator = 'authenticator:jwt';
      this.get('session').authenticate(authenticator, credentials);
    }
  }
});

I drive the values ​​into the form, press submit - an HTTP POST request is executed, which transmits
{"password":"ember","username":"ember"}
. I need to send an HTTP GET (no need to send json) with an HTTP header:
'Authorization': 'Basic ZW1iZXI6ZW1iZXI='
where ZW1iZXI6ZW1iZXI= is base64 from login:password.
Did I choose authenticator:jwt correctly? If yes, how to set it up?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Aristov, 2016-06-30
@aristov

I looked at the sources of Ember Simple Auth Token for jwt:
https://github.com/jpadilla/ember-simple-auth-toke...
1) to change the headers during authorization, you can pass them as a third parameter:
2) in the makeRequest(url, data, headers) method, the POST method is hardcoded (i.e. changing to GET will not work).
Total: Ember Simple Auth Token is not suitable for my task.

S
Stanislav Romanov, 2016-06-24
@Kaer_Morchen

Better not use ember-simple-auth-token. Instead, OAuth2, which comes with ember-simple-auth, will do.
You need to override the authenticate method , which is responsible for this case.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question