Skip to content

Migration from other libraries

Lokksmith provides the Migration utility class for migrating tokens from another OIDC library, enabling seamless user migration without requiring re-authentication.

Warning

The migration process should only be performed once for every client. It should not be used for regular token management or refresh operations.

Note

Migration is for tokens you already obtained from another library. If instead you need to log in against your own provider's custom grant type, see Extension Grants.

val lokksmith = createLokksmith()
val client = lokksmith.get("client-key")

// Replace values with actual tokens and expiration timestamps
// from other library.

lokksmith.migration.setTokens(
    client = client,
    accessToken = "ACCESS TOKEN",
    accessTokenExpiresAt = 1749471081,
    refreshToken = "REFRESH TOKEN",
    refreshTokenExpiresAt = 1752063081,
    idToken = "ID TOKEN",
)

Tip

If you're migrating tokens from AppAuth, note that AppAuth does not provide a refresh token expiration value. Use the access token's expiration time for refreshTokenExpiresAt, and then perform a token refresh immediately afterward.

lokksmith.migration.setTokens(
    client = client,
    accessToken = appAuthState.accessToken!!,
    accessTokenExpiresAt = appAuthState.accessTokenExpirationTime,
    refreshToken = appAuthState.refreshToken,
    refreshTokenExpiresAt = appAuthState.accessTokenExpirationTime, // access token refresh
    idToken = appAuthState.idToken!!,
)

client.refresh() // perform token refresh