Skip to content

Commit 44a33e2

Browse files
authored
Merge branch 'main' into sdhuka-patch-1
2 parents f46cce5 + f81521f commit 44a33e2

File tree

4 files changed

+3
-68
lines changed

4 files changed

+3
-68
lines changed

aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/HostedUIClient.kt

-10
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,6 @@ internal class HostedUIClient private constructor(
121121
return HostedUIHttpHelper.fetchTokens(createFetchTokenUrl(), createFetchTokenHeaders(), body)
122122
}
123123

124-
fun fetchRefreshedToken(refreshToken: String): CognitoUserPoolTokens {
125-
val body = mapOf(
126-
"grant_type" to "refresh_token",
127-
"client_id" to configuration.appClient,
128-
"redirect_uri" to configuration.signInRedirectURI,
129-
"refresh_token" to refreshToken
130-
)
131-
return HostedUIHttpHelper.fetchTokens(createFetchTokenUrl(), createFetchTokenHeaders(), body)
132-
}
133-
134124
private fun createAuthorizeUri(hostedUIOptions: HostedUIOptions): Uri {
135125
// Build the complete web domain to launch the login screen
136126
val builder = Uri.Builder()

aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/actions/FetchAuthSessionCognitoActions.kt

-46
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@ import aws.sdk.kotlin.services.cognitoidentityprovider.initiateAuth
2121
import aws.sdk.kotlin.services.cognitoidentityprovider.model.AuthFlowType
2222
import aws.smithy.kotlin.runtime.time.Instant
2323
import com.amplifyframework.auth.cognito.AuthEnvironment
24-
import com.amplifyframework.auth.cognito.exceptions.configuration.InvalidOauthConfigurationException
2524
import com.amplifyframework.auth.cognito.helpers.AuthHelper
2625
import com.amplifyframework.auth.cognito.helpers.SessionHelper
2726
import com.amplifyframework.auth.exceptions.NotAuthorizedException
2827
import com.amplifyframework.auth.exceptions.SessionExpiredException
2928
import com.amplifyframework.auth.exceptions.SignedOutException
30-
import com.amplifyframework.auth.exceptions.UnknownException
3129
import com.amplifyframework.statemachine.Action
3230
import com.amplifyframework.statemachine.codegen.actions.FetchAuthSessionActions
3331
import com.amplifyframework.statemachine.codegen.data.AWSCredentials
@@ -109,50 +107,6 @@ internal object FetchAuthSessionCognitoActions : FetchAuthSessionActions {
109107
dispatcher.send(evt)
110108
}
111109

112-
override fun refreshHostedUIUserPoolTokensAction(signedInData: SignedInData) =
113-
Action<AuthEnvironment>("RefreshHostedUITokens") { id, dispatcher ->
114-
logger.verbose("$id Starting execution")
115-
val evt = try {
116-
val username = signedInData.username
117-
val refreshToken = signedInData.cognitoUserPoolTokens.refreshToken
118-
if (hostedUIClient == null) throw InvalidOauthConfigurationException()
119-
if (refreshToken == null) throw UnknownException("Unable to refresh token due to missing refreshToken.")
120-
121-
val refreshedUserPoolTokens = hostedUIClient.fetchRefreshedToken(
122-
signedInData.cognitoUserPoolTokens.refreshToken
123-
).copy(
124-
// A refresh does not provide a new refresh token,
125-
// so we rebuild the new token with the old refresh token.
126-
refreshToken = signedInData.cognitoUserPoolTokens.refreshToken
127-
)
128-
129-
val updatedSignedInData = signedInData.copy(
130-
userId = refreshedUserPoolTokens.accessToken?.let(SessionHelper::getUserSub) ?: signedInData.userId,
131-
username = refreshedUserPoolTokens.accessToken?.let(SessionHelper::getUsername) ?: username,
132-
cognitoUserPoolTokens = refreshedUserPoolTokens
133-
)
134-
135-
if (configuration.identityPool != null) {
136-
val logins = LoginsMapProvider.CognitoUserPoolLogins(
137-
configuration.userPool?.region,
138-
configuration.userPool?.poolId,
139-
refreshedUserPoolTokens.idToken!!
140-
)
141-
RefreshSessionEvent(RefreshSessionEvent.EventType.RefreshAuthSession(updatedSignedInData, logins))
142-
} else {
143-
RefreshSessionEvent(RefreshSessionEvent.EventType.Refreshed(updatedSignedInData))
144-
}
145-
} catch (notAuthorized: aws.sdk.kotlin.services.cognitoidentityprovider.model.NotAuthorizedException) {
146-
// TODO: identity not authorized exception from response
147-
val error = SessionExpiredException(cause = notAuthorized)
148-
AuthorizationEvent(AuthorizationEvent.EventType.ThrowError(error))
149-
} catch (e: Exception) {
150-
AuthorizationEvent(AuthorizationEvent.EventType.ThrowError(e))
151-
}
152-
logger.verbose("$id Sending event ${evt.type}")
153-
dispatcher.send(evt)
154-
}
155-
156110
override fun refreshAuthSessionAction(logins: LoginsMapProvider) =
157111
Action<AuthEnvironment>("RefreshAuthSession") { id, dispatcher ->
158112
logger.verbose("$id Starting execution")

aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/actions/FetchAuthSessionActions.kt

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import com.amplifyframework.statemachine.codegen.data.SignedInData
2323

2424
internal interface FetchAuthSessionActions {
2525
fun refreshUserPoolTokensAction(signedInData: SignedInData): Action
26-
fun refreshHostedUIUserPoolTokensAction(signedInData: SignedInData): Action
2726
fun refreshAuthSessionAction(logins: LoginsMapProvider): Action
2827
fun fetchIdentityAction(loginsMap: LoginsMapProvider): Action
2928
fun fetchAWSCredentialsAction(identityId: String, loginsMap: LoginsMapProvider): Action

aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/RefreshSessionState.kt

+3-11
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import com.amplifyframework.statemachine.StateMachineResolver
2121
import com.amplifyframework.statemachine.StateResolution
2222
import com.amplifyframework.statemachine.codegen.actions.FetchAuthSessionActions
2323
import com.amplifyframework.statemachine.codegen.data.AmplifyCredential
24-
import com.amplifyframework.statemachine.codegen.data.SignInMethod
2524
import com.amplifyframework.statemachine.codegen.data.SignedInData
2625
import com.amplifyframework.statemachine.codegen.events.FetchAuthSessionEvent
2726
import com.amplifyframework.statemachine.codegen.events.RefreshSessionEvent
@@ -82,16 +81,9 @@ internal sealed class RefreshSessionState : State {
8281
return when (oldState) {
8382
is NotStarted -> when (refreshSessionEvent) {
8483
is RefreshSessionEvent.EventType.RefreshUserPoolTokens -> {
85-
val action = when (refreshSessionEvent.signedInData.signInMethod) {
86-
is SignInMethod.HostedUI -> {
87-
fetchAuthSessionActions.refreshHostedUIUserPoolTokensAction(
88-
refreshSessionEvent.signedInData
89-
)
90-
}
91-
else -> {
92-
fetchAuthSessionActions.refreshUserPoolTokensAction(refreshSessionEvent.signedInData)
93-
}
94-
}
84+
val action = fetchAuthSessionActions.refreshUserPoolTokensAction(
85+
refreshSessionEvent.signedInData
86+
)
9587
StateResolution(RefreshingUserPoolTokens(refreshSessionEvent.signedInData), listOf(action))
9688
}
9789
is RefreshSessionEvent.EventType.RefreshUnAuthSession -> {

0 commit comments

Comments
 (0)