All Projects → Liftric → cognito-idp

Liftric / cognito-idp

Licence: MIT License
Lightweight AWS Cognito Identity Provider client for Kotlin Multiplatform and Typescript projects.

Programming Languages

kotlin
9241 projects
swift
15916 projects

Projects that are alternatives of or similar to cognito-idp

Aws Serverless Auth Reference App
Serverless reference app and backend API, showcasing authentication and authorization patterns using Amazon Cognito, Amazon API Gateway, AWS Lambda, and AWS IAM.
Stars: ✭ 724 (+5071.43%)
Mutual labels:  auth, cognito, aws-cognito
kotlin-multiplatform-example
A Kotlin multiplatform example app that targets Android, ReactJS, iOS, JavaFx, and Spring Boot
Stars: ✭ 115 (+721.43%)
Mutual labels:  kotlin-native, kotlin-multiplatform
Arbor
Like Timber, just different
Stars: ✭ 55 (+292.86%)
Mutual labels:  kotlin-native, kotlin-multiplatform
aws-mobilehub-helper-ios
ARCHIVED: Use https://github.com/aws/aws-sdk-ios/
Stars: ✭ 41 (+192.86%)
Mutual labels:  auth, cognito
koru
Simple coroutine wrappers for Kotlin Native. Generated from annotations. Compatible with RxSwift, Combine etc.
Stars: ✭ 141 (+907.14%)
Mutual labels:  kotlin-native, kotlin-multiplatform
moko-graphics
Graphics primitives for mobile (android & ios) Kotlin Multiplatform development
Stars: ✭ 11 (-21.43%)
Mutual labels:  kotlin-native, kotlin-multiplatform
thelema-engine
Thelema - 3D graphics engine, written in Kotlin. Based on sources of libGDX.
Stars: ✭ 51 (+264.29%)
Mutual labels:  kotlin-native, kotlin-multiplatform
moko-web3
Ethereum Web3 implementation for mobile (android & ios) Kotlin Multiplatform development
Stars: ✭ 32 (+128.57%)
Mutual labels:  kotlin-native, kotlin-multiplatform
aws-amplify-react-custom-ui
Building a Custom UI Authentication For AWS Amplify
Stars: ✭ 21 (+50%)
Mutual labels:  cognito, aws-cognito
tmdb-api
This Kotlin Multiplatform library is for accessing the TMDB API to get movie and TV show content. Using for Android, iOS, and JS projects.
Stars: ✭ 31 (+121.43%)
Mutual labels:  kotlin-native, kotlin-multiplatform
chip-8
Jetpack Compose and SwiftUI based Kotlin Multiplatform fork of https://github.com/cbeust/chip-8 (Chip-8 Emulator)
Stars: ✭ 36 (+157.14%)
Mutual labels:  kotlin-native, kotlin-multiplatform
cognito-to-dynamodb-lambda
Copy newly-confirmed users from Cognito to DynamoDB
Stars: ✭ 68 (+385.71%)
Mutual labels:  cognito, aws-cognito
moko-maps
Control your map from common code for mobile (android & ios) Kotlin Multiplatform development
Stars: ✭ 47 (+235.71%)
Mutual labels:  kotlin-native, kotlin-multiplatform
amplify-material-ui
A Material-UI based implementation of aws amplify
Stars: ✭ 32 (+128.57%)
Mutual labels:  auth, cognito
kgql
GraphQL Document wrapper generator for Kotlin Multiplatform Project and Android
Stars: ✭ 54 (+285.71%)
Mutual labels:  kotlin-native, kotlin-multiplatform
SQLiter
Minimal multiplatform sqlite library
Stars: ✭ 120 (+757.14%)
Mutual labels:  kotlin-native, kotlin-multiplatform
KotlinMultiplatformAndoridParcelize
Use the Parcelize Annotation of the Kotlin Android Extensions in Kotin Multiplatform projects
Stars: ✭ 16 (+14.29%)
Mutual labels:  kotlin-native, kotlin-multiplatform
island-time
A Kotlin Multiplatform library for working with dates and times
Stars: ✭ 69 (+392.86%)
Mutual labels:  kotlin-native, kotlin-multiplatform
moko-network
Network components with codegeneration of rest api for mobile (android & ios) Kotlin Multiplatform development
Stars: ✭ 107 (+664.29%)
Mutual labels:  kotlin-native, kotlin-multiplatform
storyblok-mp-SDK
Storyblok Kotlin Multiplatform SDK (Android, JVM, JS, iOS, ...)
Stars: ✭ 16 (+14.29%)
Mutual labels:  kotlin-native, kotlin-multiplatform

CI maven-central OSS Sonatype (Releases) npm (scoped) platforms

Cognito-idp

Lightweight AWS Cognito Identity Provider client for Kotlin Multiplatform and Typescript projects.

Not all requests, errors, and auth flows are implemented.
Feel free to contribute if there is something missing for you.

Version 2 introduced breaking changes, please refer to the migration document for help.

Import

Kotlin

Gradle

sourceSets {
    val commonMain by getting {
        dependencies {
            implementation("com.liftric:cognito-idp:<version>")
        }
    }
}

Typescript

Yarn

yarn add @liftric/cognito-idp@<version>

npm

npm i @liftric/cognito-idp@<version>

How-to

Init

Kotlin

val provider = IdentityProviderClient("<region>", "<clientId>") 

Typescript

import {IdentityProviderClientJS} from '@liftric/cognito-idp';

const provider = new IdentityProviderClientJS('<region>', '<clientId>');

Usage

Kotlin

All methods are suspending and return a Result<T>, which wraps the desired object T on success or a Throwable on failure.

provider.signUp("user", "password").fold(
    onSuccess = {
        // Do something
    },
    onFailure = {
        // Handle exceptions
    }
)

Typescript

All methods return a Promise object.

Errors

Request related exceptions are defined as a sealed class of type IdentityProviderException. They contain the http status code and the message. Common AWS exceptions are implemented as subclasses. In case that we don't have implemented the exception type it will default to IdentityProviderException.Unknown, which will contain the AWS exception type.

Network related exceptions (e.g. no internet) are of type IOException.

Requests

Sign Up

Signs up the user.

Attributes are optional.

val attribute = UserAttribute("email", "[email protected]")
signUp("<username>", "<password>", listOf(attribute)): Result<SignUpResponse>

Confirm Sign Up

Confirms the sign up (also the delivery medium).

confirmSignUp("<username>", "<confirmationCode>"): Result<Unit>

Resend Confirmation Code

Resends the confirmation code.

resendConfirmationCode("<username>"): Result<CodeDeliveryDetails>

Sign In

Signs in the users.

signIn("<username>", "<password>"): Result<SignInResponse>

Refresh access token

Refreshes access token based on refresh token that's retrieved from an earlier sign in.

val signInResponse: SignInResponse = ... // from earlier login or refresh
val refreshToken = signInResponse.AuthenticationResult.RefreshToken
refresh(refreshToken): Result<SignInResponse>

Get Claims

You can retrieve the claims of both the IdTokens' and AccessTokens' payload by converting them to either a CognitoIdToken or CognitoAccessToken

val idToken = CognitoIdToken(idTokenString)
val phoneNumber = idToken.claims.phoneNumber
val sub = idToken.claims.sub

Custom attributes of the IdToken get mapped into customAttributes.

You have to drop the custom: prefix.

val twitter = idToken.claims.customAttributes["twitter"]

Get User

Returns the users attributes and metadata on success.

More info about this in the official documentation.

getUser("<accessToken>"): Result<GetUserResponse>

Update User Attributes

Updates the users attributes (e.g. email, phone number, ...).

val attributes: List<UserAttribute> = ...
updateUserAttributes("<accessToken>", attributes): Result<UpdateUserAttributesResponse>

Change Password

Updates the users password

changePassword("<accessToken>", "<currentPassword>", "<newPassword>"): Result<Unit>

Forgot Password

Invokes password forgot and sends a confirmation code the the users' delivery medium.

More info about the ForgotPasswordResponse in the official documentation.

forgotPassword("<username>"): Result<ForgotPasswordResponse>

Confirm Forgot Password

Confirms forgot password.

confirmForgotPassword("<confirmationCode>", "<username>", "<newPassword>"): Result<Unit>

Get user Attribute Verification Code

Gets the user attribute verification code for the specified attribute name

getUserAttributeVerificationCode("<accessToken>", "<attributeName>", "<clientMetadata>"): Result<GetAttributeVerificationCodeResponse>

Verify User Attribute

Verifies the specified user attribute.

verifyUserAttribute("<accessToken>", "<attributeName>", "<confirmationCode>"): Result<Unit>

Sign Out

Signs out the user globally.

signOut("<accessToken>"): Result<SignOutResponse>

Revoke Token

Revokes all access tokens generated by the refresh token.

revokeToken("<refreshToken>"): Result<Unit>

Delete User

Deletes the user from the user pool.

deleteUser("<accessToken>"): Result<Unit>

License

Cognito-idp is available under the MIT license. See the LICENSE file for more info.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].