iTwin / itwinjs-core

Monorepo for iTwin.js Library
https://www.itwinjs.org
MIT License
583 stars 211 forks source link

MobileAuthorizationFrontend.getAccessToken does not handle errors #5227

Closed tcobbs-bentley closed 1 year ago

tcobbs-bentley commented 1 year ago

Describe the bug If the native AuthorizationClient returns an error, the MobileAuthorizationFrontend.getAccessToken function produces an unhandled promise rejection, which leaves _fetchingToken true, causing all future calls to getAccessToken to simply reject. (As an aside, the reject function call doesn't provide an error, so there is no error available to see what happened.)

To Reproduce Steps to reproduce the behavior:

  1. Run the iTwin Mobile Sample app.
  2. Click on 'Hub iModels'
  3. Click 'Cancel' when prompted for permission to sign in.
  4. Go back to the Home Screen.
  5. Click on 'Hub iModels'
  6. Immediate error with no request to sign in.

Expected behavior When an AuthorizationClient calls completion(nil, nil, error) on the completion parameter of getAccessToken, this should result in either an empty string being returned from getAccessToken in the TS code, or an error being thrown. (If the latter, that is a change over past behavior, but is arguable better than returning an empty string.)

Desktop (please complete the applicable information):

tcobbs-bentley commented 1 year ago

FYI: @aruniverse, @tm-zub, @toddsouthenbentley

tcobbs-bentley commented 1 year ago

The PRs to fix this have been merged into 3.7 and master.

https://github.com/iTwin/itwinjs-core/pull/5243 https://github.com/iTwin/itwinjs-core/pull/5241