Bonjour à tous
J'utilise cette bibliothèque OAuth https://github.com/openid/AppAuth-Android
J'ai ajouté un schéma d'URL custom
1 2 3 4 5 6 7 8
| <activity android:name="net.openid.appauth.RedirectUriReceiverActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="kronos"/> <!-- Redirect URI scheme -->
</intent-filter>
</activity> |
J'ai nottamment rajouté ces méthodes :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| private void authorize() {
AuthorizationRequest authRequest = new AuthorizationRequest.Builder(
mServiceConfiguration,
"...", // Client ID
ResponseTypeValues.CODE,
Uri.parse("kronos://oauth2/callback") // Redirect URI
).setScope("auth").build();
AuthorizationService service = new AuthorizationService(this);
Intent intent = service.getAuthorizationRequestIntent(authRequest);
startActivityForResult(intent, REQUEST_CODE_AUTH);
}
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == REQUEST_CODE_AUTH) {
Log.d(TAG, "get the token");
return;
}else{
Log.d(TAG, "wrong code");
return;
} |
(https://stackoverflow.com/questions/...ion-on-android)
L'OAuth se déroule sans soucis mais j'ai besoin d'intercepter une autre URL custom par exemple "kronos://something". Celle ci sera appelé par le site lors de la déconnexion pour que, de mon coté, je supprime le token. J'aimerais pouvoir faire ce traitement dans onActivityResult mais je comprends pas comment déclencher l'appel de cette méthode
Je fait ça parce que c'est ce que a été choisis dans le cahier des charges et implémenté dans l'app iOS
D'ailleurs sous iOS je peut saisir dans safari l'URL custom et ca redirige vers l'app, est-il possible de faire cela sous Android avec chrome
EDIT
J'ai maintenant ça dans mon Manifest mais je ne comprends pas comment faire que l'app intercepte toutes les urls de commençant par "kronos://something"
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| <activity android:name="net.openid.appauth.RedirectUriReceiverActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="kronos"
android:host="oauth2"/> <!-- Redirect URI scheme -->
</intent-filter>
</activity>
<activity android:name=".activity_logoff">
<intent-filter>
<data android:scheme="kronos"
android:host="something"/> <!-- Redirect URI scheme -->
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>
</activity>
</application> |
merci d'avance
EDIT2
Voila j'ai compris qu'il fallait surement faire un Intent mais je sais pas quoi faire de cette variable
1 2
| Uri logoutUri = Uri.parse("kronos://something");
Intent logoutIntent1 = new Intent(Intent.ACTION_VIEW,logoutUri); |
EDIT3
J'ai rajouté cela
logoutIntent1.setPackage(getApplicationContext().getPackageName());
mais comment définir la fonction qui s’exécute lorsque logoutUri est appelé
Partager