Skip to content

Commit

Permalink
Merge pull request #10 from Liftric/feature/SES-feature-integration
Browse files Browse the repository at this point in the history
feat(common): Write missing cases
  • Loading branch information
gaebel authored Aug 27, 2020
2 parents b275233 + 44dcdd6 commit 34ccf19
Show file tree
Hide file tree
Showing 6 changed files with 218 additions and 117 deletions.
81 changes: 52 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,46 +55,44 @@ General usage of the request methods.
All methods are suspending and will return a `Result<T>` object which wraps the desired return object `T` and can contain an exception.

```kotlin
val signUpResponse = signUp(username = "user", password = "password")
if (signUpResponse.isSuccess) {
val response = signUp(username = "user", password = "password")
if (response.isSuccess) {
println(signUpResponse.getOrNull())
...
} else {
println(signUpResponse.exceptionOrNull())
}
```

#### Sign Up

You can sign up users by providing a username, password, and optional attributes.
Signs up the user.

Returns a parsed object on success.
Attributes are optional.

```kotlin
val attribute = UserAttribute(Name = "email", Value = "email@my.tld")
val attribute = UserAttribute(Name = "email", Value = "name@url.tld")

suspend signUp(username = "user",
password = "password",
attributes = listOf(attribute)): Result<SignUpResponse>
signUp(username = "USERNAME", password = "PASSWORD",
attributes = listOf(attribute)): Result<SignUpResponse>
...
```

#### Sign In

At the moment you can only sign in with username and password.
#### Confirm Sign Up

Returns a parsed object on success.
Confirms the sign up (also the delivery medium).

```kotlin
suspend signIn(username = "user", password = "password"): Result<SignInResponse>
confirmSignUp(username = "USERNAME", confirmationCode = "CODE_FROM_DELIVERY_MEDIUM"): Result<Unit>
```

#### Sign Out
#### Sign In

Signs in the users.

Signs out the user and returns an error if something went wrong.
At the moment you can only sign in with username and password.

```kotlin
suspend signOut(accessToken = "TOKEN_FROM_SIGN_IN_REQUEST"): Result<SignOutResponse>
signIn(username = "USERNAME", password = "PASSWORD"): Result<SignInResponse>
```

#### Get User
Expand All @@ -104,36 +102,61 @@ Returns the users attributes and metadata on success.
More info about this in the [official documentation](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_GetUser.html).

```kotlin
suspend getUser(accessToken = "TOKEN_FROM_SIGN_IN_REQUEST"): GetUserResponse
getUser(accessToken = "TOKEN_FROM_SIGN_IN_REQUEST"): GetUserResponse
```

#### Update User Attributes

Updates the users attributes (e.g. email change).

Returns a parsed object on success.
Updates the users attributes (e.g. email, phone number, ...).

```kotlin
suspend updateUserAttributes(accessToken = "TOKEN_FROM_SIGN_IN_REQUEST",
attributes = listOf(...)): Result<UpdateUserAttributesResponse>
updateUserAttributes(accessToken = "TOKEN_FROM_SIGN_IN_REQUEST",
attributes = listOf(...)): Result<UpdateUserAttributesResponse>
```

#### Change Password

Updates the users password and returns an error if something went wrong.
Updates the users password

```kotlin
changePassword(accessToken = "TOKEN_FROM_SIGN_IN_REQUEST",
currentPassword = "OLD_PW",
newPassword = "NEW_PW"): Result<Unit>
```

#### Forgot Password

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

More info about the CodeDeliveryDetails in the [official documentation](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_CodeDeliveryDetailsType.html).

```kotlin
forgotPassword(username = "USERNAME"): Result<CodeDeliveryDetails>
```

#### Confirm Forgot Password

Confirms forgot password.

```kotlin
confirmForgotPassword(username = "USERNAME", password = "NEW_PASSWORD_FROM_DELIVERY_MEDIUM",
confirmationCode = "CODE_FROM_DELIVERY_MEDIUM"): Result<Unit>
```

#### Sign Out

Signs out the user globally.

```kotlin
suspend changePassword(accessToken = "TOKEN_FROM_SIGN_IN_REQUEST",
currentPassword = "OLD_PW",
newPassword = "NEW_PW"): Result<Unit>
signOut(accessToken = "TOKEN_FROM_SIGN_IN_REQUEST"): Result<SignOutResponse>
```

#### Delete User

Deletes the user from the user pool and returns an error if something went wrong.
Deletes the user from the user pool.

```kotlin
suspend deleteUser(accessToken = "TOKEN_FROM_SIGN_IN_REQUEST"): Result<Unit>
deleteUser(accessToken = "TOKEN_FROM_SIGN_IN_REQUEST"): Result<Unit>
```

## License
Expand Down
52 changes: 38 additions & 14 deletions auth/src/commonMain/kotlin/com/liftric/Auth.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,31 @@ interface Auth {
* Signs up a new user
* @param username The username
* @param password The password
* @param attributes
* @param response Callback with error if something went wrong or an object on success
* @param attributes Optional account attributes e.g. email, phone number, ...
* @return Result object containing SignUpResponse on success or an error on failure
*/
suspend fun signUp(username: String, password: String, attributes: List<UserAttribute>? = null): Result<SignUpResponse>

/**
* Signs in the user with the given parameters
* Confirms sign up of a new user
* @param username The username
* @param password The password
* @param response Callback with error if something went wrong or an object on success
* @param confirmationCode The confirmation code that was sent to the users' delivery medium
* @return Result object containing Unit on success or an error on failure
*/
suspend fun signIn(username: String, password: String): Result<SignInResponse>
suspend fun confirmSignUp(username: String, confirmationCode: String): Result<Unit>

/**
* Signs out the user globally
* @param accessToken The access token from the sign in request
* @param response Callback with error if something went wrong
* Signs in the user with the given parameters
* @param username The username
* @param password The password
* @return Result object containing SignInResponse on success or an error on failure
*/
suspend fun signOut(accessToken: String): Result<Unit>
suspend fun signIn(username: String, password: String): Result<SignInResponse>

/**
* Fetches the user object
* @param accessToken The access token from the sign in request
* @param response Callback with error if something went wrong or an object on success
* @return Result object containing GetUserResponse on success or an error on failure
*/
suspend fun getUser(accessToken: String): Result<GetUserResponse>

Expand All @@ -39,7 +40,7 @@ interface Auth {
* e.g. email, phone number
* @param accessToken The access token from the sign in request
* @param attributes List of attributes that should be updated
* @param response Callback with error if something went wrong or an object on success
* @return Result object containing UpdateUserAttributesResponse on success or an error on failure
*/
suspend fun updateUserAttributes(accessToken: String, attributes: List<UserAttribute>): Result<UpdateUserAttributesResponse>

Expand All @@ -48,14 +49,37 @@ interface Auth {
* @param accessToken The access token from the sign in request
* @param currentPassword The password to update
* @param newPassword The new password
* @param response Callback with request response error
* @return Result object containing Unit on success or an error on failure
*/
suspend fun changePassword(accessToken: String, currentPassword: String, newPassword: String): Result<Unit>

/**
* Invokes password forgot and sends a confirmation code the the users' delivery medium
* @param username The username
* @return Result object containing CodeDeliveryDetails on success or an error on failure
*/
suspend fun forgotPassword(username: String): Result<CodeDeliveryDetails>

/**
* Confirms forgot password
* @param username The username
* @param password The new password that was sent to the users' delivery medium
* @param confirmationCode The confirmation code that was sent to the users' delivery medium
* @return Result object containing Unit on success or an error on failure
*/
suspend fun confirmForgotPassword(username: String, password: String, confirmationCode: String): Result<Unit>

/**
* Signs out the user globally
* @param accessToken The access token from the sign in request
* @return Result object containing Unit on success or an error on failure
*/
suspend fun signOut(accessToken: String): Result<Unit>

/**
* Deletes the users account
* @param accessToken The access token from the sign in request
* @param response Callback with error if something went wrong
* @return Result object containing Unit on success or an error on failure
*/
suspend fun deleteUser(accessToken: String): Result<Unit>
}
Loading

0 comments on commit 34ccf19

Please sign in to comment.