Skip to content

Commit

Permalink
Concurrency fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler committed Apr 1, 2024
1 parent 4b020eb commit db929f6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 19 deletions.
17 changes: 11 additions & 6 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.7
// swift-tools-version:5.8
//===----------------------------------------------------------------------===//
//
// This source file is part of the Soto for AWS open source project
Expand All @@ -17,6 +17,10 @@

import PackageDescription

let swiftSettings: [SwiftSetting] = [
.enableExperimentalFeature("StrictConcurrency=complete"),
]

let package = Package(
name: "soto-cognito-authentication-kit",
platforms: [
Expand All @@ -30,7 +34,7 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/apple/swift-crypto.git", .upToNextMajor(from: "1.0.0")),
.package(url: "https://github.com/soto-project/soto.git", from: "7.0.0-alpha"),
.package(url: "https://github.com/soto-project/soto.git", branch: "7.x.x"),
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.10.0"),
.package(url: "https://github.com/vapor/jwt-kit.git", .upToNextMajor(from: "4.2.6")),
// for SRP
Expand All @@ -45,17 +49,18 @@ let package = Package(
.product(name: "AsyncHTTPClient", package: "async-http-client"),
.product(name: "JWTKit", package: "jwt-kit"),
.product(name: "Crypto", package: "swift-crypto"),
]
],
swiftSettings: swiftSettings
),
.testTarget(name: "SotoCognitoAuthenticationKitTests", dependencies: ["SotoCognitoAuthenticationKit"]),

.target(
name: "SotoCognitoAuthenticationSRP",
dependencies: [
.product(name: "BigNum", package: "big-num"),
.target(name: "SotoCognitoAuthenticationKit"),
]
],
swiftSettings: swiftSettings
),
.testTarget(name: "SotoCognitoAuthenticationKitTests", dependencies: ["SotoCognitoAuthenticationKit"]),
.testTarget(name: "SotoCognitoAuthenticationSRPTests", dependencies: ["SotoCognitoAuthenticationSRP"]),
]
)
17 changes: 8 additions & 9 deletions Sources/SotoCognitoAuthenticationKit/Authenticatable+JWT.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,17 @@ extension CognitoAuthenticatable {
}

logger.debug("Load jwks.json")
let jwtSignersURL = "https://cognito-idp.\(configuration.region.rawValue).amazonaws.com/\(configuration.userPoolId)/.well-known/jwks.json"
let jwtSignersURL = URL(string: "https://cognito-idp.\(configuration.region.rawValue).amazonaws.com/\(configuration.userPoolId)/.well-known/jwks.json")!
let httpClient = configuration.cognitoIDP.client.httpClient
let response = try await httpClient.get(
url: jwtSignersURL,
deadline: .now() + .seconds(20),
let request = AWSHTTPRequest(url: jwtSignersURL, method: .GET, headers: [:], body: .init())
let response = try await httpClient.execute(
request: request,
timeout: .seconds(20),
logger: logger
).get()
)
let signers = JWTSigners()
guard let body = response.body else { return JWTSigners() }
if let data = body.getString(at: body.readerIndex, length: body.readableBytes) {
try signers.use(jwksJSON: data)
}
let data = try await response.body.collect(upTo: 1_000_000)
try signers.use(jwksJSON: String(buffer: data))
self.jwtSigners = signers
return signers
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SotoCognitoAuthenticationKit/Identifiable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import NIO
import SotoCognitoIdentity

public final class CognitoIdentifiable: Sendable {
public struct CognitoIdentifiable: Sendable {
// MARK: Member variables

/// Configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import SotoCognitoIdentity
import SotoCognitoIdentityProvider

/// Cognito authentication method used by `CredentialProviderFactory.cognitoUserPool`.
public struct CognitoAuthenticationMethod {
public struct CognitoAuthenticationMethod: Sendable {
public struct Context: Sendable {
public let authenticatable: CognitoAuthenticatable
public let userName: String
Expand Down
4 changes: 2 additions & 2 deletions Sources/SotoCognitoAuthenticationSRP/SRP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import BigNum
import Crypto
import Foundation

/// Class to generate SRP password authentication key
class SRP<H: HashFunction> {
/// Generates SRP password authentication key
struct SRP<H: HashFunction>: Sendable {
let N: BigNum
let g: BigNum
let k: BigNum
Expand Down

0 comments on commit db929f6

Please sign in to comment.