I have Identity Server 4 working with an Ionic 5 APP which works fine when I run the app in the browser. When I run it in Android studio with the emulator, I then have to make some changes to the configuration such as 10.0.2.2 to target the local IS.
When I connect to IS4 from the emulator I can see in the logs that the origin received in IS is http://localhost which makes sense since I have the APP configured in Capacitor (https://ionicframework.com/docs/troubleshooting/cors#capacitor). My problem is that when I try to redirect back, the in app browser is trying to open the URL is http://localhost/<something> which does not exist.
My question is, how can I correctly perform the redirect back to the android emulator? I can debug and I correctly sign in, but somehow when IS performs the redirect to /connect/authorize... I then get the app stuck.
capacitor.config.json:
{
"appId": "com.example.app",
"appName": "com.example.app",
"bundledWebRuntime": false,
"npmClient": "npm",
"webDir": "www",
"plugins": {
"SplashScreen": {
"launchShowDuration": 0
}
},
"cordova": {},
"allowMixedContent": true
}
My Auth configuration:
auth_config: {
identity_client: 'mobile_app',
identity_server: 'http://10.0.2.2:13810',
redirect_url: 'com.example.app://auth-callback',
end_session_redirect_url: 'com.example.app://end-session',
scopes: 'openid profile exampleapi',
usePkce: true
},
browserAuthorityUrl: 'http://localhost:13810',
Identity server client configuration:
new Client
{
ClientId = "mobile_app",
ClientName = "Mobile APP Ionic Angular 9 Client",
AllowedGrantTypes = GrantTypes.Code,
RequirePkce = true,
RequireClientSecret = false,
AllowedScopes = new List<string> { "openid", "profile", "exampleapi" },
RedirectUris = new List<string> {
$"{mobileBaseUrl}/auth-callback",
$"{mobileAppBaseUrl}auth-callback",
$"{mobileAppOrigin}/auth-callback",
},
PostLogoutRedirectUris = new List<string> {
$"{mobileBaseUrl}/end-session",
$"{mobileAppBaseUrl}end-session",
$"{mobileAppOrigin}/end-session",
},
AllowedCorsOrigins = new List<string> {
mobileBaseUrl,
mobileAppOrigin
},
AllowAccessTokensViaBrowser = true,
RequireConsent = false,
AlwaysSendClientClaims = true,
AlwaysIncludeUserClaimsInIdToken = true,
}
where
"mobileBaseUrl": "http://localhost:8100",
"mobileAppBaseUrl": "com.example.app://",
"mobileAppOrigin": "http://localhost",
Note that works perfectly fine using the app via ionic serve but it fails when I run the Android app within the emulator. I'm following the example and using the ionic-appauth package from here: https://github.com/wi3land/ionic-appauth-capacitor-demo
UPDATE: The URL it is stuck on is when the user is authenticated and Identity server is redirecting to: /connect/authorize/callback?redirect_uri=com.example.app%3A%2F%2Fauth-callback&client_id=mobile_app&response_type=code&state=rLv7spCgZ2&scope=openid%20profile%20exampleapi&code_challenge=9yGKbchJ7YII2tx3jHAmcnV90kYZxsYVWz-60Ge5TQQ&code_challenge_method=S256