Skip to content

Commit

Permalink
Authenticator fix
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-lsvk committed Sep 20, 2023
1 parent 8c7fe98 commit 6fdb97c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

public protocol ClientIdAuthenticating {
func createAuthToken() throws -> String
func createAuthToken(url: String?) throws -> String
}

public struct ClientIdAuthenticator: ClientIdAuthenticating {
Expand All @@ -13,9 +13,9 @@ public struct ClientIdAuthenticator: ClientIdAuthenticating {
self.url = url
}

public func createAuthToken() throws -> String {
public func createAuthToken(url: String? = nil) throws -> String {
let keyPair = try clientIdStorage.getOrCreateKeyPair()
let payload = RelayAuthPayload(subject: getSubject(), audience: url)
let payload = RelayAuthPayload(subject: getSubject(), audience: url ?? self.url)
return try payload.signAndCreateWrapper(keyPair: keyPair).jwtString
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/WalletConnectRelay/RelayURLFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct RelayUrlFactory {
URLQueryItem(name: "projectId", value: projectId)
]
do {
let authToken = try socketAuthenticator.createAuthToken()
let authToken = try socketAuthenticator.createAuthToken(url: fallback ? "wss://" + NetworkConstants.fallbackUrl : "wss://" + relayHost)
components.queryItems?.append(URLQueryItem(name: "auth", value: authToken))
} catch {
// TODO: Handle token creation errors
Expand Down

0 comments on commit 6fdb97c

Please sign in to comment.