-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(auth): Create use cases for device management APIs (#2979)
Co-authored-by: Tyler Roach <[email protected]>
- Loading branch information
1 parent
de59bc4
commit 9dbd9f4
Showing
19 changed files
with
489 additions
and
314 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...h-cognito/src/main/java/com/amplifyframework/auth/cognito/usecases/FetchDevicesUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package com.amplifyframework.auth.cognito.usecases | ||
|
||
import aws.sdk.kotlin.services.cognitoidentityprovider.CognitoIdentityProviderClient | ||
import aws.sdk.kotlin.services.cognitoidentityprovider.listDevices | ||
import com.amplifyframework.auth.AuthDevice | ||
import com.amplifyframework.auth.cognito.AuthStateMachine | ||
import com.amplifyframework.auth.cognito.requireSignedInState | ||
|
||
internal class FetchDevicesUseCase( | ||
private val client: CognitoIdentityProviderClient, | ||
private val fetchAuthSession: FetchAuthSessionUseCase, | ||
private val stateMachine: AuthStateMachine | ||
) { | ||
suspend fun execute(): List<AuthDevice> { | ||
stateMachine.requireSignedInState() | ||
val token = fetchAuthSession.execute().accessToken | ||
val response = client.listDevices { accessToken = token } | ||
return response.devices?.map { device -> | ||
val id = device.deviceKey ?: "" | ||
val name = device.deviceAttributes?.find { it.name == "device_name" }?.value | ||
AuthDevice.fromId(id, name) | ||
} ?: emptyList() | ||
} | ||
} |
Oops, something went wrong.