I am writing an Android application that consumes the Drupal 8 REST features. I have managed to write REST resources and make API calls with the android app to these resources with success.

My question is about the login and sessions. When the users logs in for the first time we get X-CSRF-Token, which has an expiration date. I also use this token to authenticate myself when making calls to the REST resources.

Does Drupal has a REST feature that refreshes the token without having to enter the user credentials again?

The idea is to have an app on which you log in only once until the users logs out manually.

1 Answer 1


Rasjaad, You can use android account manager https://developer.android.com/reference/android/accounts/AccountManager for this purpose

Here is a sample Drupal 8 Android app code that uses account manager to reauthenticate. https://github.com/onedrupal/One-Drupal-Android

https://github.com/onedrupal/One-Drupal-Android/blob/master/app/src/main/java/com/technikh/onedrupal/activities/ActivityAuthentication.java At the launch of the activity AccountManager.getAuthTokenByFeatures is called

mAccountManager.getAuthTokenByFeatures(AccountUtils.ACCOUNT_TYPE, AccountUtils.AUTH_TOKEN_TYPE, null, this, null, null, new ActivityAuthentication.GetAuthTokenCallback(), null);

Here is the AccountAuthenticator https://github.com/onedrupal/One-Drupal-Android/blob/master/app/src/main/java/com/technikh/onedrupal/authenticator/AccountAuthenticator.java

authToken = AccountUtils.mServerAuthenticator.signIn(site_protocol+site_domain, account.name, password);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.