Skip to content

Commit f3bcede

Browse files
committed
update snippets
1 parent 419b92d commit f3bcede

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

snippets.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,10 @@
155155
{
156156
"step": 3,
157157
"description": "Trigger login with offline_access and capture the refresh token",
158-
"code": " suspend fun signIn(): Intent? {\n _error.value = null\n val issuerJavaUri = AuthConfig.issuer\n ?: run { _error.value = \"CIAM_ISSUER_HOST is missing — fill in local.properties\"; return null }\n if (AuthConfig.clientId.isEmpty()) {\n _error.value = \"CIAM_CLIENT_ID is missing — fill in local.properties\"; return null\n }\n val redirect = AuthConfig.redirectUri\n ?: run { _error.value = \"CIAM_REDIRECT_SCHEME is missing — fill in local.properties\"; return null }\n return try {\n val issuerAndroidUri = Uri.parse(issuerJavaUri.toString())\n val config = discoverConfiguration(issuerAndroidUri)\n val request = AuthorizationRequest.Builder(\n config,\n AuthConfig.clientId,\n ResponseTypeValues.CODE,\n redirect,\n )\n .setScopes(AuthConfig.scopes)\n .build()\n // Assign pendingAuthState only after the Intent is successfully created so\n // a thrown getAuthorizationRequestIntent doesn't leave stale state behind.\n // Catch Exception (not Throwable) so coroutine CancellationException still\n // propagates and structured concurrency works correctly.\n val intent = authService.getAuthorizationRequestIntent(request)\n pendingAuthState = AuthState(config)\n intent\n } catch (e: Exception) {\n _error.value = e.localizedMessage ?: \"Authorization failed\"\n null\n }\n }",
158+
"code": " suspend fun signIn(): Intent? {\n _error.value = null\n val issuerJavaUri = AuthConfig.issuer\n ?: run { _error.value = \"CIAM_ISSUER_HOST is missing — fill in local.properties\"; return null }\n if (AuthConfig.clientId.isEmpty()) {\n _error.value = \"CIAM_CLIENT_ID is missing — fill in local.properties\"; return null\n }\n val redirect = AuthConfig.redirectUri\n ?: run { _error.value = \"CIAM_REDIRECT_SCHEME is missing — fill in local.properties\"; return null }\n return try {\n val issuerAndroidUri = Uri.parse(issuerJavaUri.toString())\n val config = discoverConfiguration(issuerAndroidUri)\n val request = AuthorizationRequest.Builder(\n config,\n AuthConfig.clientId,\n ResponseTypeValues.CODE,\n redirect,\n )\n .setScopes(AuthConfig.scopes)\n .build()\n val intent = authService.getAuthorizationRequestIntent(request)\n pendingAuthState = AuthState(config)\n intent\n } catch (e: Exception) {\n _error.value = e.localizedMessage ?: \"Authorization failed\"\n null\n }\n }",
159159
"file": "app/src/main/java/com/secureauth/quickstart/AuthViewModel.kt",
160160
"lang": "kotlin",
161-
"lines": "96-129"
161+
"lines": "96-125"
162162
},
163163
{
164164
"step": 4,
@@ -174,7 +174,7 @@
174174
"code": " suspend fun refreshTokens() {\n _error.value = null\n val issuerJavaUri = AuthConfig.issuer\n ?: run { _error.value = \"CIAM_ISSUER_HOST is missing — fill in local.properties\"; return }\n if (AuthConfig.clientId.isEmpty()) {\n _error.value = \"CIAM_CLIENT_ID is missing — fill in local.properties\"; return\n }\n val storedRefresh = _tokens.value?.refreshToken?.takeIf { it.isNotEmpty() }\n ?: store.load()\n ?: run { _error.value = \"No refresh token available. Sign in first.\"; return }\n try {\n val config = discoverConfiguration(Uri.parse(issuerJavaUri.toString()))\n val request = TokenRequest.Builder(config, AuthConfig.clientId)\n .setGrantType(GrantTypeValues.REFRESH_TOKEN)\n .setRefreshToken(storedRefresh)\n .build()\n val response = performTokenRequest(request)\n val next = toTokens(response, fallback = _tokens.value)\n _tokens.value = next\n // If the IdP rotated the refresh token, persist the new one.\n if (next.refreshToken != null && next.refreshToken != storedRefresh) {\n persistRefreshToken(next.refreshToken)\n }\n scheduleRefreshTimer()\n } catch (e: Exception) {\n // Refresh tokens can be revoked or expire — clear local state and force re-login.\n store.clear()\n _tokens.value = null\n refreshJob?.cancel()\n _error.value = \"Refresh failed (${e.localizedMessage}). Sign in again.\"\n }\n }",
175175
"file": "app/src/main/java/com/secureauth/quickstart/AuthViewModel.kt",
176176
"lang": "kotlin",
177-
"lines": "163-196"
177+
"lines": "157-190"
178178
}
179179
],
180180
"framework": "android",

0 commit comments

Comments
 (0)