Search code examples
cordovaauthenticationionic-frameworkionic2auth0

Authparams in auth0js


i need to set additional parameters in auth0 to make the audience url work correctly. In authlock you can simply do this:

 var lock = new Auth0Lock('clientID', 'account.auth0.com', {
auth: {
 params: {
  audience: 'url'
  }
 }
});

I guess I need to add the code to my auth0config within my authservice but i'm not sure what and how:

 const auth0Config = {
 // needed for auth0
 clientID: 'id',

 // needed for auth0cordova
 clientId: 'id',
 domain: 'url',
 callbackURL: location.href,
 packageIdentifier: 'id',

};

Who can tell me how to do it?


Solution

  • For the Auth0 ionic 2 quickstart, tried adding audience here (along with updating scope info):

    Reading the source, expected this to work since later on when the cordova library uses auth0.js, it eventually calls this code and should merge the baseOptions with passed in Options. However, for some reason didn't seem to work.

    Instead, I had to force the baseOptions by adding an extra entry here for the audience in the Cordova library itself eg.

    function CordovaAuth(options) {
      this.clientId = options.clientId;
      this.domain = options.domain;
      this.redirectUri = options.packageIdentifier + '://' + options.domain + '/cordova/' + options.packageIdentifier + '/callback';
      this.client = new auth0.Authentication({
        clientID: this.clientId,
        domain: this.domain,
        // just hard coded here for time being - need a check to see if present first..
        audience: options.audience, 
        _telemetryInfo: telemetry
      });
    }
    

    And then pass the audience in here instead - this is the same section of code you put in your question. Doing the above does work, and produces a JWT Access token with supplied scopes, but unclear why simply adding audience to options did not work instead...

    Interesting the API seems to indicate that it expects audience and this line suggests the audience would be propogated and used to build the authorizeUrl here.

    Have left an open issue with the Auth0 quickstarts team to clarify. But the above solution will allow you to work with a JWT Access token in meantime. You can either fork the repo and control it that way, or just for testing go ahead and edit the source inside your node_modules folder to check it works for you.

    Shall post an update on this answer once I hear back from the Auth0 quickstarts team regarding the "official" solution to this.