fenichelar/ember-simple-auth-token

How can I auth with a custom token returning endpoint?

Redsandro opened this issue · 2 comments

When I have a custom endpoint that returns the necessary token and refreshToken, how can I continue authenticating the Ember app?

Normally you would call the token or jwt authenticator from ember-simple-auth, which calls authenticate(credentials) on ember-simple-auth-jwt like so:

this.get('session').authenticate('authenticator:jwt', credentials)

Now if you have an API endpoint that returns the JWT when e.g. a facebook oauth token is submitted in stead of the default user credentials. How do you skip ember-simple-auth-token's authenticate and pass the token directly to handleAuthResponse?

This is what I came up with, but I am not sure if this is the correct way to do it, or if it has any unforseen complications.

app/authenticators/custom-jwt.js:

import JWT from 'ember-simple-auth-token/authenticators/jwt'

export default JWT.extend({
	authenticate(args) {
		return this.handleAuthResponse(args)
	}
})

Login:

this.get('session').authenticate('authenticator:custom-jwt')
stale commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.