Skip to content

Commit

Permalink
feat(Auth): Implementation of getCurrentUser api (#455)
Browse files Browse the repository at this point in the history
  • Loading branch information
royjit authored May 21, 2020
1 parent 43e3a70 commit 59f6b18
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import AWSMobileClient

/// Auth plugin that uses AWS Cognito UserPool and IdentityPool.
///
/// The implicitly unwrapped optionals in this class are assigned in the `configure` method in `AWSCognitoAuthPlugin+Configure`
/// extension. Make sure to call `Amplify.configure` after adding the plugin to `Amplify`.
/// The implicitly unwrapped optionals in this class are assigned in the `configure` method in
/// `AWSCognitoAuthPlugin+Configure` extension. Make sure to call `Amplify.configure` after adding the
/// plugin to `Amplify`.
final public class AWSCognitoAuthPlugin: AuthCategoryPlugin {

/// A queue that regulates the execution of operations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,4 @@ extension AWSCognitoAuthPlugin {
queue.addOperation(operation)
return operation
}

public func getCurrentUser() -> AuthUser? {
return nil
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,8 @@ extension AWSCognitoAuthPlugin {
queue.addOperation(operation)
return operation
}

public func getCurrentUser() -> AuthUser? {
return authenticationProvider.getCurrentUser()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ class AuthenticationProviderAdapter: AuthenticationProviderBehavior {
self.awsMobileClient = awsMobileClient
}

func signInUsername() -> Result<String, AuthError> {
func getCurrentUser() -> AuthUser? {

if let username = awsMobileClient.username() {
return .success(username)
guard let username = awsMobileClient.getUsername() else {
return nil
}
// TODO: Fix the error here
return .failure(AuthError.unknown(""))

guard let sub = awsMobileClient.getUserSub() else {
return nil
}
return AWSAuthUser(username: username, userId: sub)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protocol AuthenticationProviderBehavior {
func signOut(request: AuthSignOutRequest,
completionHandler: @escaping (Result<Void, AuthError>) -> Void)

func signInUsername() -> Result<String, AuthError>
func getCurrentUser() -> AuthUser?

func resetPassword(request: AuthResetPasswordRequest,
completionHandler: @escaping (Result<AuthResetPasswordResult, AuthError>) -> Void)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ import Amplify

public struct AWSAuthUser: AuthUser {

/// The username for the logged in user
///
/// Value maps to the username of a user in AWS Cognito User Pool. This value is set by AWS Cognito and not by the
/// user and does not always map with the username used to signIn.
public var username: String

/// User Id for the logged in user
///
/// UserId value maps to the sub value of a user in AWS Cognito User Pool. This value will be unique for a user.
public var userId: String

}
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,14 @@ class AWSMobileClientAdapter: AWSMobileClientBehavior {
awsMobileClient.signOut()
}

func username() -> String? {
func getUsername() -> String? {
return awsMobileClient.username
}

func getUserSub() -> String? {
return awsMobileClient.userSub
}

func verifyUserAttribute(attributeName: String,
completionHandler: @escaping ((UserCodeDeliveryDetails?, Error?) -> Void)) {
awsMobileClient.verifyUserAttribute(attributeName: attributeName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ protocol AWSMobileClientBehavior {

func signOutLocally()

func username() -> String?
func getUsername() -> String?

func getUserSub() -> String?

func verifyUserAttribute(attributeName: String,
completionHandler: @escaping ((UserCodeDeliveryDetails?, Error?) -> Void))
Expand Down
26 changes: 13 additions & 13 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
PODS:
- AWSAuthCore (2.13.3):
- AWSCore (= 2.13.3)
- AWSCognitoIdentityProvider (2.13.3):
- AWSAuthCore (2.13.4):
- AWSCore (= 2.13.4)
- AWSCognitoIdentityProvider (2.13.4):
- AWSCognitoIdentityProviderASF (= 1.0.1)
- AWSCore (= 2.13.3)
- AWSCore (= 2.13.4)
- AWSCognitoIdentityProviderASF (1.0.1)
- AWSCore (2.13.3)
- AWSMobileClient (2.13.3):
- AWSAuthCore (= 2.13.3)
- AWSCognitoIdentityProvider (= 2.13.3)
- AWSCore (2.13.4)
- AWSMobileClient (2.13.4):
- AWSAuthCore (= 2.13.4)
- AWSCognitoIdentityProvider (= 2.13.4)
- CwlCatchException (1.0.2)
- CwlPreconditionTesting (1.1.1):
- CwlCatchException
Expand All @@ -24,7 +24,7 @@ DEPENDENCIES:
- SwiftLint

SPEC REPOS:
https://cdn.cocoapods.org/:
trunk:
- AWSAuthCore
- AWSCognitoIdentityProvider
- AWSCognitoIdentityProviderASF
Expand All @@ -50,11 +50,11 @@ CHECKOUT OPTIONS:
:tag: 1.2.0

SPEC CHECKSUMS:
AWSAuthCore: 93b71ac38596e75790015c7299c725bb09ae1d5f
AWSCognitoIdentityProvider: 3480819d983e78eda7a43e141273756784be30cb
AWSAuthCore: 72b4bd064c28985ea5345c62759632d511de342a
AWSCognitoIdentityProvider: a2d1d2857316519c018c03ac8205cf78154db5c0
AWSCognitoIdentityProviderASF: f94f1a502e72ef3d0a1de93e10bf7a79c8698118
AWSCore: fc361166b595e3c0183c55987743b295646c39d2
AWSMobileClient: 9149b664d1a89279bd49d36598c7afc38a63d7d1
AWSCore: 06beea22b6bdbfe9f5ab5015c6901e8475c746a8
AWSMobileClient: 33ecce524fbc011d543dae8306ca29a43ecb72e5
CwlCatchException: 70a52ae44ea5d46db7bd385f801a94942420cd8c
CwlPreconditionTesting: d33a4e4f285c0b885fddcae5dfedfbb34d4f3961
SwiftFormat: b72e592ea0979aeee53f6052abff291181364933
Expand Down
26 changes: 13 additions & 13 deletions Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 59f6b18

Please sign in to comment.