From d8e190373476be95753f8cf075e067ce767613f4 Mon Sep 17 00:00:00 2001 From: Daniel Lindau Date: Fri, 15 Mar 2024 11:05:57 +0100 Subject: [PATCH] Include expiresIn from the tokenResponse --- .../java/io/curity/haapi/react/HaapiModule.kt | 3 +- ios/HaapiModule/HaapiModule.swift | 30 +++++++++++-------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/android/src/main/java/io/curity/haapi/react/HaapiModule.kt b/android/src/main/java/io/curity/haapi/react/HaapiModule.kt index 669a8a4..6c3e3ec 100644 --- a/android/src/main/java/io/curity/haapi/react/HaapiModule.kt +++ b/android/src/main/java/io/curity/haapi/react/HaapiModule.kt @@ -211,7 +211,8 @@ class HaapiModule(private val _reactContext: ReactApplicationContext) : ReactCon "accessToken" to tokenResponse.accessToken, "refreshToken" to tokenResponse.refreshToken, "scope" to tokenResponse.scope, - "idToken" to tokenResponse.idToken + "idToken" to tokenResponse.idToken, + "expiresIn" to tokenResponse.expiresIn.seconds ) _tokenResponse = tokenResponse resolveRequest("TokenResponse", _gson.toJson(tokenMap), promise) diff --git a/ios/HaapiModule/HaapiModule.swift b/ios/HaapiModule/HaapiModule.swift index e1d9be8..7ba6db5 100644 --- a/ios/HaapiModule/HaapiModule.swift +++ b/ios/HaapiModule/HaapiModule.swift @@ -224,7 +224,7 @@ class HaapiModule: RCTEventEmitter { private func handle(tokenResponse: TokenResponse, promise: Promise) { switch(tokenResponse) { case .successfulToken(let successfulTokenResponse): - let tokenResponse = self.mapTokenResponse(successfulTokenResponse) + let tokenResponse = SuccessTokenResponse(successfulTokenResponse) resolveRequest(eventType: EventType.TokenResponse, body: tokenResponse, promise: promise) case .errorToken(let errorTokenResponse): // Request succeeded, but with contents indicating an. Resolve with contents, so that frontend can act on it. @@ -247,18 +247,6 @@ class HaapiModule: RCTEventEmitter { }) } - private func mapTokenResponse(_ succesfulTokenResponse: SuccessfulTokenResponse) -> Dictionary { - var tokenResponse = ["accessToken": succesfulTokenResponse.accessToken] - if (succesfulTokenResponse.idToken != nil) { - tokenResponse["idToken"] = succesfulTokenResponse.idToken - } - if (succesfulTokenResponse.refreshToken != nil) { - tokenResponse["refreshToken"] = succesfulTokenResponse.refreshToken - } - tokenResponse["scope"] = succesfulTokenResponse.scope ?? "" - return tokenResponse - } - private func sendHaapiEvent(_ type: EventType, body: Codable, promise: Promise) { do { let encodedBody = try encodeObject(body) @@ -297,4 +285,20 @@ class HaapiModule: RCTEventEmitter { } } + private struct SuccessTokenResponse : Codable { + var accessToken: String + var refreshToken: String? + var idToken: String? + var scope: String + var expiresIn: Int + + init(_ tokenResponse : SuccessfulTokenResponse) { + self.accessToken = tokenResponse.accessToken + self.idToken = tokenResponse.idToken + self.refreshToken = tokenResponse.refreshToken + self.scope = tokenResponse.scope ?? "" + self.expiresIn = tokenResponse.expiresIn + } + } + }