This repository has been archived by the owner on Nov 15, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f38f908
commit 35237d7
Showing
43 changed files
with
835 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# IAM Identity Center | ||
|
||
The IAMIdentityCenter connector provides the following Fakes: | ||
|
||
## OIDC | ||
|
||
Actions: | ||
* RegisterClient | ||
* StartDeviceAuthentication | ||
* CreateToken | ||
|
||
### Default Fake port: 34160 | ||
|
||
To start: | ||
|
||
``` | ||
FakeOIDC().start() | ||
``` | ||
|
||
## SSO | ||
|
||
Actions: | ||
* SSO: GetFederatedCredentials | ||
|
||
### Default Fake port: 25813 | ||
|
||
To start: | ||
|
||
``` | ||
FakeSSO().start() | ||
``` | ||
|
||
## Interactive CLI login | ||
|
||
The module provides a CredentialsProvider to do interactive login to | ||
|
||
```kotlin | ||
val provider = CredentialsProvider.SSO( | ||
SSOProfile( | ||
AwsAccount.of("01234567890"), | ||
RoleName.of("hello"), | ||
Region.US_EAST_1, | ||
Uri.of("http://foobar"), | ||
) | ||
) | ||
``` |
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,12 @@ | ||
import Libs.api | ||
|
||
dependencies { | ||
api(project(":http4k-connect-amazon-core")) | ||
api(Libs.http4k_format_moshi) { | ||
exclude("org.jetbrains.kotlin", "kotlin-reflect") | ||
} | ||
implementation(Libs.api) | ||
|
||
testImplementation(project(path = ":http4k-connect-core", configuration = "testArtifacts")) | ||
testImplementation(project(path = ":http4k-connect-amazon-core", configuration = "testArtifacts")) | ||
} |
24 changes: 24 additions & 0 deletions
24
...titycenter/client/src/main/kotlin/org/http4k/connect/amazon/iamidentitycenter/HttpOIDC.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,24 @@ | ||
package org.http4k.connect.amazon.iamidentitycenter | ||
|
||
import org.http4k.client.JavaHttpClient | ||
import org.http4k.connect.amazon.core.model.Region | ||
import org.http4k.core.HttpHandler | ||
import org.http4k.core.Uri | ||
import org.http4k.core.then | ||
import org.http4k.filter.ClientFilters | ||
import org.http4k.filter.ClientFilters.SetXForwardedHost | ||
|
||
/** | ||
* Standard HTTP implementation of OIDC | ||
*/ | ||
fun OIDC.Companion.Http( | ||
region: Region, | ||
http: HttpHandler = JavaHttpClient(), | ||
) = object : OIDC { | ||
private val routedHttp = ClientFilters.SetHostFrom(Uri.of("https://oidc.$region.amazonaws.com")) | ||
.then(SetXForwardedHost()) | ||
.then(http) | ||
|
||
override fun <R : Any> invoke(action: OIDCAction<R>) = action.toResult(routedHttp(action.toRequest())) | ||
} | ||
|
23 changes: 23 additions & 0 deletions
23
...ntitycenter/client/src/main/kotlin/org/http4k/connect/amazon/iamidentitycenter/HttpSSO.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,23 @@ | ||
package org.http4k.connect.amazon.iamidentitycenter | ||
|
||
import org.http4k.client.JavaHttpClient | ||
import org.http4k.connect.amazon.core.model.Region | ||
import org.http4k.core.HttpHandler | ||
import org.http4k.core.Uri | ||
import org.http4k.core.then | ||
import org.http4k.filter.ClientFilters | ||
|
||
/** | ||
* Standard HTTP implementation of SSO | ||
*/ | ||
fun SSO.Companion.Http( | ||
region: Region, | ||
http: HttpHandler = JavaHttpClient(), | ||
) = object : SSO { | ||
|
||
private val routedHttp = ClientFilters.SetHostFrom(Uri.of("https://portal.sso.$region.amazonaws.com")) | ||
.then(ClientFilters.SetXForwardedHost()) | ||
.then(http) | ||
|
||
override fun <R : Any> invoke(action: SSOAction<R>) = action.toResult(routedHttp(action.toRequest())) | ||
} |
48 changes: 48 additions & 0 deletions
48
...ient/src/main/kotlin/org/http4k/connect/amazon/iamidentitycenter/IAMIdentiyCenterMoshi.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,48 @@ | ||
package org.http4k.connect.amazon.iamidentitycenter | ||
|
||
import com.squareup.moshi.JsonAdapter | ||
import com.squareup.moshi.Moshi | ||
import org.http4k.connect.amazon.iamidentitycenter.model.AccessToken | ||
import org.http4k.connect.amazon.iamidentitycenter.model.ClientId | ||
import org.http4k.connect.amazon.iamidentitycenter.model.ClientName | ||
import org.http4k.connect.amazon.iamidentitycenter.model.ClientSecret | ||
import org.http4k.connect.amazon.iamidentitycenter.model.DeviceCode | ||
import org.http4k.connect.amazon.iamidentitycenter.model.IdToken | ||
import org.http4k.connect.amazon.iamidentitycenter.model.RefreshToken | ||
import org.http4k.connect.amazon.iamidentitycenter.model.RoleName | ||
import org.http4k.connect.amazon.iamidentitycenter.model.SessionId | ||
import org.http4k.connect.amazon.iamidentitycenter.model.UserCode | ||
import org.http4k.format.AwsCoreJsonAdapterFactory | ||
import org.http4k.format.ConfigurableMoshi | ||
import org.http4k.format.ListAdapter | ||
import org.http4k.format.MapAdapter | ||
import org.http4k.format.asConfigurable | ||
import org.http4k.format.value | ||
import org.http4k.format.withAwsCoreMappings | ||
import org.http4k.format.withStandardMappings | ||
import se.ansman.kotshi.KotshiJsonAdapterFactory | ||
|
||
object IAMIdentityCenterMoshi : ConfigurableMoshi( | ||
Moshi.Builder() | ||
.add(IAMIdentityCenterJsonAdapterFactory) | ||
.add(AwsCoreJsonAdapterFactory()) | ||
.add(ListAdapter) | ||
.add(MapAdapter) | ||
.asConfigurable() | ||
.withStandardMappings() | ||
.value(AccessToken) | ||
.value(ClientName) | ||
.value(ClientId) | ||
.value(ClientSecret) | ||
.value(DeviceCode) | ||
.value(IdToken) | ||
.value(RefreshToken) | ||
.value(SessionId) | ||
.value(RoleName) | ||
.value(UserCode) | ||
.withAwsCoreMappings() | ||
.done() | ||
) | ||
|
||
@KotshiJsonAdapterFactory | ||
object IAMIdentityCenterJsonAdapterFactory : JsonAdapter.Factory by KotshiIAMIdentityCenterJsonAdapterFactory |
17 changes: 17 additions & 0 deletions
17
...identitycenter/client/src/main/kotlin/org/http4k/connect/amazon/iamidentitycenter/OIDC.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,17 @@ | ||
package org.http4k.connect.amazon.iamidentitycenter | ||
|
||
import dev.forkhandles.result4k.Result | ||
import org.http4k.connect.Http4kConnectAdapter | ||
import org.http4k.connect.RemoteFailure | ||
import org.http4k.connect.amazon.AwsServiceCompanion | ||
|
||
/** | ||
* Docs: https://docs.aws.amazon.com/singlesignon/latest/OIDCAPIReference/Welcome.html | ||
*/ | ||
@Http4kConnectAdapter | ||
interface OIDC { | ||
operator fun <R : Any> invoke(action: OIDCAction<R>): Result<R, RemoteFailure> | ||
|
||
companion object : AwsServiceCompanion("oidc") | ||
} | ||
|
6 changes: 6 additions & 0 deletions
6
...tycenter/client/src/main/kotlin/org/http4k/connect/amazon/iamidentitycenter/OIDCAction.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,6 @@ | ||
package org.http4k.connect.amazon.iamidentitycenter | ||
|
||
import org.http4k.connect.NonNullAutoMarshalledAction | ||
import kotlin.reflect.KClass | ||
|
||
abstract class OIDCAction<R : Any>(clazz: KClass<R>) : NonNullAutoMarshalledAction<R>(clazz, IAMIdentityCenterMoshi) |
13 changes: 13 additions & 0 deletions
13
...midentitycenter/client/src/main/kotlin/org/http4k/connect/amazon/iamidentitycenter/SSO.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,13 @@ | ||
package org.http4k.connect.amazon.iamidentitycenter | ||
|
||
import dev.forkhandles.result4k.Result | ||
import org.http4k.connect.Http4kConnectAdapter | ||
import org.http4k.connect.RemoteFailure | ||
import org.http4k.connect.amazon.AwsServiceCompanion | ||
|
||
@Http4kConnectAdapter | ||
interface SSO { | ||
operator fun <R : Any> invoke(action: SSOAction<R>): Result<R, RemoteFailure> | ||
|
||
companion object : AwsServiceCompanion("sso") | ||
} |
6 changes: 6 additions & 0 deletions
6
...itycenter/client/src/main/kotlin/org/http4k/connect/amazon/iamidentitycenter/SSOAction.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,6 @@ | ||
package org.http4k.connect.amazon.iamidentitycenter | ||
|
||
import org.http4k.connect.NonNullAutoMarshalledAction | ||
import kotlin.reflect.KClass | ||
|
||
abstract class SSOAction<R : Any>(clazz: KClass<R>) : NonNullAutoMarshalledAction<R>(clazz, IAMIdentityCenterMoshi) |
8 changes: 8 additions & 0 deletions
8
...r/client/src/main/kotlin/org/http4k/connect/amazon/iamidentitycenter/model/AccessToken.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,8 @@ | ||
package org.http4k.connect.amazon.iamidentitycenter.model | ||
|
||
import dev.forkhandles.values.NonBlankStringValueFactory | ||
import dev.forkhandles.values.StringValue | ||
|
||
class AccessToken private constructor(value: String) : StringValue(value) { | ||
companion object : NonBlankStringValueFactory<AccessToken>(::AccessToken) | ||
} |
8 changes: 8 additions & 0 deletions
8
...nter/client/src/main/kotlin/org/http4k/connect/amazon/iamidentitycenter/model/ClientId.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,8 @@ | ||
package org.http4k.connect.amazon.iamidentitycenter.model | ||
|
||
import dev.forkhandles.values.NonBlankStringValueFactory | ||
import dev.forkhandles.values.StringValue | ||
|
||
class ClientId private constructor(value: String) : StringValue(value) { | ||
companion object : NonBlankStringValueFactory<ClientId>(::ClientId) | ||
} |
8 changes: 8 additions & 0 deletions
8
...er/client/src/main/kotlin/org/http4k/connect/amazon/iamidentitycenter/model/ClientName.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,8 @@ | ||
package org.http4k.connect.amazon.iamidentitycenter.model | ||
|
||
import dev.forkhandles.values.NonBlankStringValueFactory | ||
import dev.forkhandles.values.StringValue | ||
|
||
class ClientName private constructor(value: String) : StringValue(value) { | ||
companion object : NonBlankStringValueFactory<ClientName>(::ClientName) | ||
} |
8 changes: 8 additions & 0 deletions
8
.../client/src/main/kotlin/org/http4k/connect/amazon/iamidentitycenter/model/ClientSecret.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,8 @@ | ||
package org.http4k.connect.amazon.iamidentitycenter.model | ||
|
||
import dev.forkhandles.values.NonBlankStringValueFactory | ||
import dev.forkhandles.values.StringValue | ||
|
||
class ClientSecret private constructor(value: String) : StringValue(value) { | ||
companion object : NonBlankStringValueFactory<ClientSecret>(::ClientSecret) | ||
} |
8 changes: 8 additions & 0 deletions
8
...er/client/src/main/kotlin/org/http4k/connect/amazon/iamidentitycenter/model/DeviceCode.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,8 @@ | ||
package org.http4k.connect.amazon.iamidentitycenter.model | ||
|
||
import dev.forkhandles.values.NonBlankStringValueFactory | ||
import dev.forkhandles.values.StringValue | ||
|
||
class DeviceCode private constructor(value: String) : StringValue(value) { | ||
companion object : NonBlankStringValueFactory<DeviceCode>(::DeviceCode) | ||
} |
8 changes: 8 additions & 0 deletions
8
...enter/client/src/main/kotlin/org/http4k/connect/amazon/iamidentitycenter/model/IdToken.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,8 @@ | ||
package org.http4k.connect.amazon.iamidentitycenter.model | ||
|
||
import dev.forkhandles.values.NonBlankStringValueFactory | ||
import dev.forkhandles.values.StringValue | ||
|
||
class IdToken private constructor(value: String) : StringValue(value) { | ||
companion object : NonBlankStringValueFactory<IdToken>(::IdToken) | ||
} |
8 changes: 8 additions & 0 deletions
8
.../client/src/main/kotlin/org/http4k/connect/amazon/iamidentitycenter/model/RefreshToken.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,8 @@ | ||
package org.http4k.connect.amazon.iamidentitycenter.model | ||
|
||
import dev.forkhandles.values.NonBlankStringValueFactory | ||
import dev.forkhandles.values.StringValue | ||
|
||
class RefreshToken private constructor(value: String) : StringValue(value) { | ||
companion object : NonBlankStringValueFactory<RefreshToken>(::RefreshToken) | ||
} |
8 changes: 8 additions & 0 deletions
8
...nter/client/src/main/kotlin/org/http4k/connect/amazon/iamidentitycenter/model/RoleName.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,8 @@ | ||
package org.http4k.connect.amazon.iamidentitycenter.model | ||
|
||
import dev.forkhandles.values.NonBlankStringValueFactory | ||
import dev.forkhandles.values.StringValue | ||
|
||
class RoleName private constructor(value: String) : StringValue(value) { | ||
companion object : NonBlankStringValueFactory<RoleName>(::RoleName) | ||
} |
12 changes: 12 additions & 0 deletions
12
...er/client/src/main/kotlin/org/http4k/connect/amazon/iamidentitycenter/model/SSOProfile.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,12 @@ | ||
package org.http4k.connect.amazon.iamidentitycenter.model | ||
|
||
import org.http4k.connect.amazon.core.model.AwsAccount | ||
import org.http4k.connect.amazon.core.model.Region | ||
import org.http4k.core.Uri | ||
|
||
data class SSOProfile( | ||
val accountId: AwsAccount, | ||
val roleName: RoleName, | ||
val region: Region, | ||
val startUri: Uri | ||
) |
8 changes: 8 additions & 0 deletions
8
...ter/client/src/main/kotlin/org/http4k/connect/amazon/iamidentitycenter/model/SessionId.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,8 @@ | ||
package org.http4k.connect.amazon.iamidentitycenter.model | ||
|
||
import dev.forkhandles.values.NonBlankStringValueFactory | ||
import dev.forkhandles.values.StringValue | ||
|
||
class SessionId private constructor(value: String) : StringValue(value) { | ||
companion object : NonBlankStringValueFactory<SessionId>(::SessionId) | ||
} |
9 changes: 9 additions & 0 deletions
9
...nter/client/src/main/kotlin/org/http4k/connect/amazon/iamidentitycenter/model/UserCode.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,9 @@ | ||
package org.http4k.connect.amazon.iamidentitycenter.model | ||
|
||
import dev.forkhandles.values.NonBlankStringValueFactory | ||
import dev.forkhandles.values.StringValue | ||
|
||
class UserCode private constructor(value: String) : StringValue(value) { | ||
companion object : NonBlankStringValueFactory<UserCode>(::UserCode) | ||
} | ||
|
47 changes: 47 additions & 0 deletions
47
...nt/src/main/kotlin/org/http4k/connect/amazon/iamidentitycenter/oidc/action/CreateToken.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,47 @@ | ||
package org.http4k.connect.amazon.iamidentitycenter.oidc.action | ||
|
||
import org.http4k.connect.Http4kConnectAction | ||
import org.http4k.connect.amazon.iamidentitycenter.IAMIdentityCenterMoshi | ||
import org.http4k.connect.amazon.iamidentitycenter.OIDCAction | ||
import org.http4k.connect.amazon.iamidentitycenter.model.AccessToken | ||
import org.http4k.connect.amazon.iamidentitycenter.model.ClientId | ||
import org.http4k.connect.amazon.iamidentitycenter.model.ClientSecret | ||
import org.http4k.connect.amazon.iamidentitycenter.model.DeviceCode | ||
import org.http4k.connect.amazon.iamidentitycenter.model.IdToken | ||
import org.http4k.connect.amazon.iamidentitycenter.model.RefreshToken | ||
import org.http4k.connect.amazon.iamidentitycenter.model.SessionId | ||
import org.http4k.connect.kClass | ||
import org.http4k.core.Method | ||
import org.http4k.core.Request | ||
import org.http4k.core.with | ||
import se.ansman.kotshi.JsonSerializable | ||
|
||
@Http4kConnectAction | ||
data class CreateToken( | ||
val clientId: ClientId, | ||
val clientSecret: ClientSecret, | ||
val deviceCode: DeviceCode, | ||
) : OIDCAction<DeviceToken>(kClass()) { | ||
override fun toRequest() = Request(Method.POST, "token") | ||
.with( | ||
IAMIdentityCenterMoshi.autoBody<Any>().toLens() of mapOf( | ||
"clientId" to clientId, | ||
"clientSecret" to clientSecret, | ||
"deviceCode" to deviceCode, | ||
"grantType" to "urn:ietf:params:oauth:grant-type:device_code" | ||
) | ||
) | ||
} | ||
|
||
|
||
@JsonSerializable | ||
data class DeviceToken( | ||
val accessToken: AccessToken, | ||
val expiresIn: Long, | ||
val idToken: IdToken?, | ||
val refreshToken: RefreshToken?, | ||
val aws_sso_app_session_id: SessionId?, | ||
val originSessionId: SessionId?, | ||
val issuedTokenType: String?, | ||
val tokenType: String, | ||
) |
Oops, something went wrong.