2

Ember app is using adfs login. when a successful login adfs will redirect to ember web app with a route and query parameters. those query parameters contain

access_token
refresh_token
user_id
scope

i need to update session of the ember auth with those credential data. how can i achieve this ?

2 Answers2

2

You will need to authenticate a session with you params.
In order to being able to authenticate your session you will need to create an authenticator. Basically, this will provide you some method to being able to handle your session (invalidateSession, authenticate, restoreSession etc..).
For the authenticator creation check out http://ember-simple-auth.com/api/classes/BaseAuthenticator.html It will look like something like so https://jsfiddle.net/e7nzoa6y/ but that's not exclusive you will have to custom it with you endpoint and stuff

Then once you have your authenticator, check out the doc at http://ember-simple-auth.com/api/classes/BaseAuthenticator.html

In your controller, after injecting the session service, you will be able to call the function authenticate with something looking like

this.session.authenticate(
  'authenticator:YOUR_AUTHENTICATOR', queryParams
);
Djamel
  • 798
  • 8
  • 21
1

djamel your answer works for me and i have modified the code using your example as below

import Base from 'ember-simple-auth/authenticators/base';
import {
  isEmpty
} from '@ember/utils';
export default Base.extend({
  authenticate(data) {
     return new Promise((resolve, reject) => {

       if(data.access_token!=null){
       resolve({

                     access_token: data.access_token,
                     id: data.id,
                     agreement:data.agreement
                   });
   }else{
    reject();
   }  })

  },

 restore(data) {
   console.log(data)
    return new Promise((resolve, reject) => {

      if (!isEmpty(data.access_token)) {
        resolve(data);
      } else {
        reject();
      }    });
  }
});

other than that i had to add

ENV['ember-simple-auth'] = { routeAfterAuthentication: 'authenticated.index' },

in config environment as well.