Oauth2 doesn't redirect to my flutter application after successful login
I am trying to implement oauth2 with flutter_appauth
package. After successful login the web page should redirect to my mobile application. At this moment, it just stays in web (redirecting to web home page). I'm currently getting this error
Redirect to scheme 'com.app.app` is not permitted.
Here is the code
oauth2.dart
Future<void> login() async {
try {
final AuthorizationTokenResponse result =
await appAuth.authorizeAndExchangeCode(
AuthorizationTokenRequest(
'client_id',
'com.app.app:/oauthredirect',
// discoveryUrl:
// "http://10.0.2.2:8000/api/oauth2/.well-known/openid-configuration",
serviceConfiguration: const AuthorizationServiceConfiguration(
authorizationEndpoint: 'http://10.0.2.2:8000/api/oauth2/authorize',
tokenEndpoint: 'http://10.0.2.2:8000/api/oauth2/token',
),
scopes: ['openid', 'profile', 'email'],
),
);
print("Received Token!");
// Successfully received the token
print(result);
} catch (e) {
print('Login error: $e');
}
}
build.gradle
defaultConfig {
applicationId "com.app.app"
minSdkVersion 26
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
manifestPlaceholders += [appAuthRedirectScheme: 'com.app.app']
}
Note: login()
function invoked when user clicks the login button on the login screen. Also, I've tried implementing oauth2 with discoveryUrl
and it just crashes the app immediately after login()
function is called. Last thing I want to mention is I have already checked redirection uri in admin panel and it's correct. Oauth2 was implemented with Django oauth2 toolkit.