Initialisation
SuperTokensInterceptor
to your OkHttpClient
1) Add the This library provides an Interceptor
to allow simple integration with OkHttp
or Retrofit
.
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
clientBuilder.interceptors().add(new SuperTokensInterceptor());
clientBuilder.cookieJar(new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(context))); // sets persistent cookies
OkHttpClient client = clientBuilder.build();
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
clientBuilder.interceptors().add(new SuperTokensInterceptor());
clientBuilder.cookieJar(new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(context))); // sets persistent cookies
OkHttpClient client = clientBuilder.build();
Retrofit instance = new Retrofit.Builder()
.baseUrl("YOUR BASE URL")
.client(client)
.build();
SuperTokens.init
function: API Reference
2) Call The - To be called at least once before any http request is made to any of your APIs that require authentication.
- You only need to call this once in your app.
import io.supertokens.session.SuperTokens
try {
SuperTokens.init(getApplication(), "https://api.example.com/session/refresh", 401, null);
} catch (MalformedURLException e) {
// Refresh URL was invalid
}
import io.supertokens.session.SuperTokens
try {
SuperTokens.init(application, "https://api.example.com/session/refresh", 401, null);
} catch (MalformedURLException e) {
// Refresh URL was invalid
}
- To understand the various parameters, please visit the API reference link above.