From f5931b00f213939b3c29509ba9ce841f245f9fba Mon Sep 17 00:00:00 2001 From: Samuel Gulliksson Date: Wed, 31 Aug 2022 11:03:56 +0200 Subject: [PATCH] Cleanup fixes (#53) * Make idToken a property of User (instead of function). * Remove Client.cachedUser completely. --- .../com/schibsted/account/webflows/client/Client.kt | 10 +--------- .../com/schibsted/account/webflows/user/User.kt | 13 ++++++++----- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/webflows/src/main/java/com/schibsted/account/webflows/client/Client.kt b/webflows/src/main/java/com/schibsted/account/webflows/client/Client.kt index 3254011b..a0010696 100644 --- a/webflows/src/main/java/com/schibsted/account/webflows/client/Client.kt +++ b/webflows/src/main/java/com/schibsted/account/webflows/client/Client.kt @@ -211,24 +211,16 @@ class Client : ClientInterface { } } - private var cashedUser: User? = null - /** Resume any previously logged-in user session */ override fun resumeLastLoggedInUser(callback: (Either) -> Unit) { sessionStorage.get(configuration.clientId) { result -> result .foreach { storedUserSession: StoredUserSession? -> if (storedUserSession == null) { - cashedUser = null callback(Right(null)) } else { val user = User(this, storedUserSession.userTokens) - if (user.equals(cashedUser)) { - callback(Right(cashedUser)) - } else { - cashedUser = user - callback(Right(cashedUser)) - } + callback(Right(user)) } } .left().foreach { diff --git a/webflows/src/main/java/com/schibsted/account/webflows/user/User.kt b/webflows/src/main/java/com/schibsted/account/webflows/user/User.kt index 9f3c84e3..1b45a4d1 100644 --- a/webflows/src/main/java/com/schibsted/account/webflows/user/User.kt +++ b/webflows/src/main/java/com/schibsted/account/webflows/user/User.kt @@ -47,6 +47,14 @@ class User { tokens.idTokenClaims.sub } + /** + * ID Token + */ + val idToken: String + get() = onlyIfLoggedIn { tokens -> + tokens.idToken + } + constructor(client: Client, session: UserSession) : this(client, session.tokens) internal constructor(client: Client, tokens: UserTokens) { @@ -86,11 +94,6 @@ class User { client.schibstedAccountApi.userProfile(this, callback) } - /** - * Get idToken for User - * */ - fun getIdToken(): String? = tokens?.idToken - /** * Generate URL with embedded one-time code for creating a web session for the current user. *