@@ -21,13 +21,11 @@ import aws.sdk.kotlin.services.cognitoidentityprovider.initiateAuth
21
21
import aws.sdk.kotlin.services.cognitoidentityprovider.model.AuthFlowType
22
22
import aws.smithy.kotlin.runtime.time.Instant
23
23
import com.amplifyframework.auth.cognito.AuthEnvironment
24
- import com.amplifyframework.auth.cognito.exceptions.configuration.InvalidOauthConfigurationException
25
24
import com.amplifyframework.auth.cognito.helpers.AuthHelper
26
25
import com.amplifyframework.auth.cognito.helpers.SessionHelper
27
26
import com.amplifyframework.auth.exceptions.NotAuthorizedException
28
27
import com.amplifyframework.auth.exceptions.SessionExpiredException
29
28
import com.amplifyframework.auth.exceptions.SignedOutException
30
- import com.amplifyframework.auth.exceptions.UnknownException
31
29
import com.amplifyframework.statemachine.Action
32
30
import com.amplifyframework.statemachine.codegen.actions.FetchAuthSessionActions
33
31
import com.amplifyframework.statemachine.codegen.data.AWSCredentials
@@ -109,50 +107,6 @@ internal object FetchAuthSessionCognitoActions : FetchAuthSessionActions {
109
107
dispatcher.send(evt)
110
108
}
111
109
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
-
156
110
override fun refreshAuthSessionAction (logins : LoginsMapProvider ) =
157
111
Action <AuthEnvironment >(" RefreshAuthSession" ) { id, dispatcher ->
158
112
logger.verbose(" $id Starting execution" )
0 commit comments