From 8a8c6dad5d2fae434805962d6fc1ed57d6a1a2bc Mon Sep 17 00:00:00 2001 From: Alexander Lisovik Date: Mon, 2 Oct 2023 11:11:57 +0400 Subject: [PATCH] Update authenticator url --- .../ClientAuth/ClientIdAuthenticator.swift | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Sources/WalletConnectRelay/ClientAuth/ClientIdAuthenticator.swift b/Sources/WalletConnectRelay/ClientAuth/ClientIdAuthenticator.swift index 468a1cf5e..87a7daada 100644 --- a/Sources/WalletConnectRelay/ClientAuth/ClientIdAuthenticator.swift +++ b/Sources/WalletConnectRelay/ClientAuth/ClientIdAuthenticator.swift @@ -4,9 +4,9 @@ public protocol ClientIdAuthenticating { func createAuthToken(url: String?) throws -> String } -public struct ClientIdAuthenticator: ClientIdAuthenticating { +public final class ClientIdAuthenticator: ClientIdAuthenticating { private let clientIdStorage: ClientIdStoring - private let url: String + private var url: String public init(clientIdStorage: ClientIdStoring, url: String) { self.clientIdStorage = clientIdStorage @@ -14,8 +14,10 @@ public struct ClientIdAuthenticator: ClientIdAuthenticating { } public func createAuthToken(url: String? = nil) throws -> String { + url.flatMap { self.url = $0 } + let keyPair = try clientIdStorage.getOrCreateKeyPair() - let payload = RelayAuthPayload(subject: getSubject(), audience: url ?? self.url) + let payload = RelayAuthPayload(subject: getSubject(), audience: self.url) return try payload.signAndCreateWrapper(keyPair: keyPair).jwtString }