Skip to content

Commit

Permalink
Merge pull request #1124 from WalletConnect/authenticator-fix
Browse files Browse the repository at this point in the history
[Relay] Authenticator Fix
  • Loading branch information
alexander-lsvk authored Oct 2, 2023
2 parents 0266213 + 8a8c6da commit 2e1b67d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import Foundation

public protocol ClientIdAuthenticating {
func createAuthToken() throws -> String
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
self.url = url
}

public func createAuthToken() throws -> String {
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)
let payload = RelayAuthPayload(subject: getSubject(), audience: 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 2e1b67d

Please sign in to comment.