I am a newbie in flutter and I am using visual studio code for my development. I have been tasked by my company to implement oauth2 in flutter for one of our clients. I have read the implementation guide on flutter_web_auth through this link https://pub.dev/packages/flutter_web_auth_2 and the possible cause of not being redirected back to your app after authorization on stack overflow. None seems to work for me.
After authorization, I don't get redirected to my app hence no Authorization Code Grant Response. I've spent close to 2 days I am wondering if someone can point me in the right direction. The value in my callbackUrlScheme is 'https'
redirect_uri is https://example.com/api/external/client/hybridflow/callback
Please note: I am just using example.com in place of the real domain name or host .
and my AndroidManifest.xml containing verified Applink status below
<activity android:name="com.linusu.flutter_web_auth_2.CallbackActivity" android:exported="true">
<intent-filter android:label="flutter_web_auth_2" android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https"
android:host="example.com"
android:pathPrefix="/api/external/client/hybridflow/callback" />
</intent-filter>
</activity>
And here is my code
class ExternalClientOauthService {
var logger = Logger(
filter: null,
printer: PrettyPrinter(),
output: null,
);
Future<String> getExternalClientAuthorizationAsync(
String signedauthorizeRequestUrl,
[String oauthCallbackUrlScheme = '']) async {
try {
final result = await FlutterWebAuth.authenticate(
url: signedauthorizeRequestUrl,
callbackUrlScheme: oauthCallbackUrlScheme,
);
return result;
} on SocketException catch (e) {
logger.e(e);
rethrow;
} on HttpException catch (e) {
logger.e(e);
rethrow;
} on FormatException catch (e) {
logger.e(e);
rethrow;
} on PlatformException catch (e) {
logger.e(e);
rethrow;
} finally {}
}
}
Future<String> _getAuthorizationAsync(String signAuthorizeRequestUrl,
[String customCallbackUrlScheme = '']) {
var aouthRequest = _oauthExternalService.getExternalClientAuthorizationAsync(
signAuthorizeRequestUrl, customCallbackUrlScheme);
return aouthRequest;
}
String url = 'https://api.xxxx.com/oauth/authorize'
'?client_id=xxxxxx'
'&redirect_uri=https%3A%2F%2Fexample.com%2Fapi%2Fexternal%2Fclient%2Fhybridflow%2Fcallback'
'&response_type=code';
var authorizeurl = Uri.parse(url).toString();
var authorizationCodGrantResponse =
await _getAuthorizationAsync(authorizeurl,
'https');
The code above is called here below
Possible cause of not being redirected back to your app after authorization on stack overflow. None of the solutions in the links below work for me.