azure-activedirectory-library-for-cordova icon indicating copy to clipboard operation
azure-activedirectory-library-for-cordova copied to clipboard

msadal - acquireTokenSilentAsync doesn't works until "userId" is passed, even it is optional as per docs.

Open gg0305 opened this issue 4 years ago • 5 comments

I've encountered an issue while using 'acquireTokenSilentAsync()' through 'msadal' in 'ionic v5'.

Its given in docs that 'userId' is optional.

Docs:

Expected:

/**
 * Acquires token WITHOUT using interactive flow. It checks the cache to return existing result
 * if not expired. It tries to use refresh token if available. If it fails to get token without
 * displaying UI it will fail. This method guarantees that no UI will be shown to user.
 *
 * @param   {String}  resourceUrl Resource identifier
 * @param   {String}  clientId    Client (application) identifier
 * @param   {String}  userId      User identifier (optional)
 * @returns {Promise} Promise either fulfilled with AuthenticationResult object or rejected with error
 */
acquireTokenSilentAsync(resourceUrl: string, clientId: string, userId?: string): Promise<AuthenticationResult>;

Error:

Wrong type for parameter "userId" of AuthenticationContext.acquireTokenSilentAsync: Expected String, but got Function.
TypeError: Wrong type for parameter "userId" of AuthenticationContext.acquireTokenSilentAsync: Expected String, but got Function.

But, method doesn't make call until I passed an empty string as the parameter.

Workaround:

// request for token using configuration from environment.
this.authContext.acquireTokenSilentAsync(msadalConfig.resourceUrl, msadalConfig.clientId, "")

gg0305 avatar Apr 10 '20 14:04 gg0305

@gg0305 This library is archived and they haven't been updating the acquireTokenSilentAsync signature methods. I ended up using a forked version where the signature api reflects the native acquireTokenSilentAsync api.

leewhitbeck avatar Apr 17 '20 21:04 leewhitbeck

@leewhitbeck did have the url of forked rep ? is there any forked rep that fixed the problem of UiWebView ?

fradali avatar Apr 22 '20 11:04 fradali

@fradali , here is the forked repo we used. We have the app disabled, but I don't think it has fixed the UiWebView issue.

leewhitbeck avatar Apr 23 '20 16:04 leewhitbeck

@gg0305 did you find a solution ?

GroupeBEL avatar May 03 '20 04:05 GroupeBEL

@webteambel which solution? the "userID" to be passed?

gg0305 avatar May 03 '20 10:05 gg0305