Skip to content

Commit

Permalink
Fix JWT construction in iOS
Browse files Browse the repository at this point in the history
ref #38
  • Loading branch information
louischan-oursky committed Apr 8, 2024
2 parents 7d7f0f5 + 6d9ed5a commit 4f79b87
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ios/Classes/SwiftAuthgearPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -788,15 +788,15 @@ public class SwiftAuthgearPlugin: NSObject, FlutterPlugin, ASWebAuthenticationPr
private func signJWT(privateKey: SecKey, header: [String: Any], payload: [String: Any]) -> Result<String, Error> {
let headerJSON = JSONSerialization.serialize(value: header)
let payloadJSON = JSONSerialization.serialize(value: payload)
let headerString = headerJSON.base64EncodedString()
let payloadString = payloadJSON.base64EncodedString()
let headerString = headerJSON.base64urlEncodedString()
let payloadString = payloadJSON.base64urlEncodedString()
let strToSign = "\(headerString).\(payloadString)"
let dataToSign = strToSign.data(using: .utf8)!
switch self.signData(privateKey: privateKey, data: dataToSign) {
case .failure(let error):
return .failure(error)
case .success(let signature):
let signatureStr = signature.base64EncodedString()
let signatureStr = signature.base64urlEncodedString()
let jwt = "\(strToSign).\(signatureStr)"
return .success(jwt)
}
Expand Down

0 comments on commit 4f79b87

Please sign in to comment.