jeudi 23 février 2017

A token request using ember-simple-auth-token won't include the identification field

A have an Ember (v2.12.0-beta.1) app that uses ember-simple-auth-token to request a JWT token.

The important part happens in the login controller.

export default Ember.Controller.extend({
    session: Ember.inject.service(),

    // Properties
    username: 'user1',
    password: 'password123',

    // Actions
    actions: {
        login(username, password) {
            console.log('Attempting login...');

            let creds = this.getProperties('username', 'password');
            let authenticator = 'authenticator:jwt';

            this.get('session').authenticate(authenticator, creds).then(function() {
                console.log('LOGIN SUCCESS')
            }, function() {
                console.log('LOGIN FAIL')
            });
        }
    }
});

When submitting the form, there is a request that is being made by the browser and my backend receives it.

The problem is that only the password is included in the request. The body of the request has the form {"password":"password123"}, but it should look like {"username":"user1","password":"password123"}. If course, the login attempt fails and LOGIN FAIL is printed.

When is the username not included in the token request?

I tried using earlier versions of ember-simple-auth-token and ember-simple-auth.

Here is my configuration:

ENV['ember-simple-auth'] = {
    authorizer: 'authorizer:token',
};

ENV['ember-simple-auth-token'] = {
    serverTokenEndpoint: 'http://ift.tt/2mj58Q4',
    identificationField: 'username',
    passwordField: 'password',
    tokenPropertyName: 'token',
    authorizationPrefix: 'Bearer ',
    authorizationHeaderName: 'Authorization',
    refreshAccessTokens: false,
};




Aucun commentaire:

Enregistrer un commentaire