From ac3610d87af96dc9565413167d419cd0bad1db8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tautvydas=20S=CC=8Cidlauskas?= Date: Mon, 27 Mar 2023 11:02:58 +0300 Subject: [PATCH] fix: do not hide PlatformException Previously if user manually closed web view it was not possible to indicate that. --- lib/oauth2_client.dart | 54 +++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/lib/oauth2_client.dart b/lib/oauth2_client.dart index 3e13a6e..38544b8 100644 --- a/lib/oauth2_client.dart +++ b/lib/oauth2_client.dart @@ -152,37 +152,33 @@ class OAuth2Client { codeChallenge = OAuth2Utils.generateCodeChallenge(codeVerifier); } - try { - var authResp = await requestAuthorization( - webAuthClient: webAuthClient, - clientId: clientId, - scopes: scopes, - codeChallenge: codeChallenge, - enableState: enableState, - state: state, - customParams: authCodeParams, - webAuthOpts: webAuthOpts); - - if (authResp.isAccessGranted()) { - if (afterAuthorizationCodeCb != null) { - afterAuthorizationCodeCb(authResp); - } + var authResp = await requestAuthorization( + webAuthClient: webAuthClient, + clientId: clientId, + scopes: scopes, + codeChallenge: codeChallenge, + enableState: enableState, + state: state, + customParams: authCodeParams, + webAuthOpts: webAuthOpts); - tknResp = await requestAccessToken( - httpClient: httpClient, - //If the authorization request was successfull, the code must be set - //otherwise an exception is raised in the OAuth2Response constructor - code: authResp.code!, - clientId: clientId, - scopes: scopes, - clientSecret: clientSecret, - codeVerifier: codeVerifier, - customParams: accessTokenParams, - customHeaders: accessTokenHeaders); - } else { - tknResp = AccessTokenResponse.errorResponse(); + if (authResp.isAccessGranted()) { + if (afterAuthorizationCodeCb != null) { + afterAuthorizationCodeCb(authResp); } - } on PlatformException { + + tknResp = await requestAccessToken( + httpClient: httpClient, + //If the authorization request was successful, the code must be set + //otherwise an exception is raised in the OAuth2Response constructor + code: authResp.code!, + clientId: clientId, + scopes: scopes, + clientSecret: clientSecret, + codeVerifier: codeVerifier, + customParams: accessTokenParams, + customHeaders: accessTokenHeaders); + } else { tknResp = AccessTokenResponse.errorResponse(); }