Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ GEM
base64
nkf
rexml
activesupport (7.2.2.1)
activesupport (7.2.3.1)
base64
benchmark (>= 0.3)
bigdecimal
Expand All @@ -14,11 +14,11 @@ GEM
drb
i18n (>= 1.6, < 2)
logger (>= 1.4.2)
minitest (>= 5.1)
minitest (>= 5.1, < 6)
securerandom (>= 0.3)
tzinfo (~> 2.0, >= 2.0.5)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
addressable (2.9.0)
public_suffix (>= 2.0.2, < 8.0)
algoliasearch (1.27.5)
httpclient (~> 2.8, >= 2.8.3)
json (>= 1.5.1)
Expand Down Expand Up @@ -105,7 +105,7 @@ GEM
ethon (0.16.0)
ffi (>= 1.15.0)
excon (0.112.0)
faraday (1.10.4)
faraday (1.10.5)
faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
faraday-excon (~> 1.1)
Expand Down
77 changes: 42 additions & 35 deletions Sources/Authgear.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ struct AuthenticateOptions {

var request: OIDCAuthenticationRequest {
let scopes = getAuthenticationScopes(
preAuthenticatedURLEnabled: preAuthenticatedURLEnabled)
preAuthenticatedURLEnabled: preAuthenticatedURLEnabled
)
return OIDCAuthenticationRequest(
redirectURI: self.redirectURI,
responseType: "code",
Expand Down Expand Up @@ -581,14 +582,16 @@ public class Authgear {
let userInfo = try apiClient.syncRequestOIDCUserInfo(accessToken: oidcTokenResponse.accessToken!)

persistSession(oidcTokenResponse, reason: .authenticated) { result in
handler(result.flatMap {
Result { () in
if #available(iOS 11.3, *) {
try self.disableBiometric()
handler(
result.flatMap {
Result { () in
if #available(iOS 11.3, *) {
try self.disableBiometric()
}
}
}
}
.map { userInfo })
.map { userInfo }
)
}
} catch {
return handler(.failure(wrapError(error: error)))
Expand Down Expand Up @@ -927,15 +930,17 @@ public class Authgear {
let userInfo = try self.apiClient.syncRequestOIDCUserInfo(accessToken: oidcTokenResponse.accessToken!)

self.persistSession(oidcTokenResponse, reason: .authenticated) { result in
handler(result.flatMap {
Result { () in
try self.storage.setAnonymousKeyId(namespace: self.name, kid: keyId)
if #available(iOS 11.3, *) {
try self.disableBiometric()
handler(
result.flatMap {
Result { () in
try self.storage.setAnonymousKeyId(namespace: self.name, kid: keyId)
if #available(iOS 11.3, *) {
try self.disableBiometric()
}
}
}
}
.map { userInfo })
.map { userInfo }
)
}
} catch {
handler(.failure(wrapError(error: error)))
Expand Down Expand Up @@ -1697,7 +1702,8 @@ public class Authgear {
accessToken: nil,
xApp2AppDeviceKeyJwt: nil,
scope: getAuthenticationScopes(
preAuthenticatedURLEnabled: self.preAuthenticatedURLEnabled),
preAuthenticatedURLEnabled: self.preAuthenticatedURLEnabled
),
requestedTokenType: nil,
subjectTokenType: nil,
subjectToken: nil,
Expand Down Expand Up @@ -1735,28 +1741,29 @@ public class Authgear {
self.workerQueue.async {
do {
try self.app2app.startAuthenticateRequest(
request: request) { success in
do {
// If failed to start, fail immediately
try success.get()
} catch {
handler(.failure(wrapError(error: error)))
}
var unsubscribe: (() -> Void)?
unsubscribe = self.app2app.listenToApp2AppAuthenticationResult(
redirectUri: request.redirectUri.absoluteString
) { [weak self] resultURL in
unsubscribe?()
guard let this = self else {
return
}
this.finishAuthentication(
url: resultURL,
verifier: verifier,
handler: handler
)
request: request
) { success in
do {
// If failed to start, fail immediately
try success.get()
} catch {
handler(.failure(wrapError(error: error)))
}
var unsubscribe: (() -> Void)?
unsubscribe = self.app2app.listenToApp2AppAuthenticationResult(
redirectUri: request.redirectUri.absoluteString
) { [weak self] resultURL in
unsubscribe?()
guard let this = self else {
return
}
this.finishAuthentication(
url: resultURL,
verifier: verifier,
handler: handler
)
}
}
} catch {
handler(.failure(wrapError(error: error)))
}
Expand Down
35 changes: 25 additions & 10 deletions Sources/AuthgearError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ public enum AuthgearError: CustomNSError, LocalizedError {
case runtimeError(String)
case preAuthenticatedURLNotAllowed(PreAuthenticatedURLNotAllowedError)

// Implements CustomNSError
public static var errorDomain: String { "AuthgearError" }
/// Implements CustomNSError
public static var errorDomain: String {
"AuthgearError"
}

public var errorCode: Int {
switch self {
case .cancel:
Expand Down Expand Up @@ -95,7 +98,7 @@ public enum AuthgearError: CustomNSError, LocalizedError {
return info
}

// Implements LocalizedError
/// Implements LocalizedError
public var errorDescription: String? {
var message = ""
switch self {
Expand Down Expand Up @@ -160,9 +163,15 @@ public struct OAuthError: LocalizedError, CustomNSError, Decodable {
self.errorUri = errorUri
}

// Implements CustomNSError
public static var errorDomain: String { "OAuthError" }
public var errorCode: Int { 0 }
/// Implements CustomNSError
public static var errorDomain: String {
"OAuthError"
}

public var errorCode: Int {
0
}

public var errorUserInfo: [String: Any] {
var userInfo: [String: Any] = [
"error": self.error
Expand Down Expand Up @@ -198,9 +207,15 @@ public struct ServerError: CustomNSError, LocalizedError, Decodable {
info = try? values.decode([String: Any].self, forKey: .info)
}

// Implements CustomNSError
public static var errorDomain: String { "ServerError" }
public var errorCode: Int { 0 }
/// Implements CustomNSError
public static var errorDomain: String {
"ServerError"
}

public var errorCode: Int {
0
}

public var errorUserInfo: [String: Any] {
var userInfo: [String: Any] = [
"name": self.name,
Expand All @@ -213,7 +228,7 @@ public struct ServerError: CustomNSError, LocalizedError, Decodable {
return userInfo
}

// Implements LocalizedError
/// Implements LocalizedError
public var errorDescription: String? {
let message = "\(reason): \(message)"
return "\(Self.errorDomain): \(message)"
Expand Down
3 changes: 1 addition & 2 deletions Sources/Biometric.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ func getPrivateKey(tag: String, laContext: LAContext) throws -> SecKey? {
throw NSError(domain: NSOSStatusErrorDomain, code: Int(status))
}

let privateKey = item as! SecKey
return privateKey
return item as! SecKey
}

@available(iOS 11.3, *)
Expand Down
3 changes: 1 addition & 2 deletions Sources/JWK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ struct JWKStore {

switch status {
case errSecSuccess:
let privateKey = item as! SecKey
return privateKey
return item as! SecKey
case errSecItemNotFound:
return nil
default:
Expand Down
3 changes: 1 addition & 2 deletions Sources/JWT.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ struct JWTSigner {
let fixlenR = Asn1IntegerConversion.toRaw(varlenR, of: crv.coordinateOctetLength)
let fixlenS = Asn1IntegerConversion.toRaw(varlenS, of: crv.coordinateOctetLength)

let fixedSignature = (fixlenR + fixlenS)
return fixedSignature
return (fixlenR + fixlenS)
}

func sign(header: String, payload: String) throws -> String {
Expand Down
3 changes: 1 addition & 2 deletions Sources/Storage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,7 @@ class KeychainStorageDriver {

switch status {
case errSecSuccess:
let value = String(data: result as! Data, encoding: .utf8)!
return value
return String(data: result as! Data, encoding: .utf8)!
case errSecItemNotFound:
return nil
default:
Expand Down
3 changes: 2 additions & 1 deletion Sources/String+encodeAsQueryComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ private extension CharacterSet {
extension String {
func encodeAsQueryComponent() -> String? {
self.addingPercentEncoding(
withAllowedCharacters: CharacterSet.queryComponentAllowed)
withAllowedCharacters: CharacterSet.queryComponentAllowed
)
}
}
6 changes: 2 additions & 4 deletions Sources/app2app/App2App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ class App2App {
throw NSError(domain: NSOSStatusErrorDomain, code: Int(status))
}

let privateKey = item as! SecKey
return privateKey
return item as! SecKey
}

private func openURLInUniversalLink(
Expand Down Expand Up @@ -133,8 +132,7 @@ class App2App {
let header = JWTHeader(typ: .app2app, jwk: jwk, includeJWK: true)
let payload = JWTPayload(challenge: challenge, action: App2AppPayloadAction.setup.rawValue)
let jwt = JWT(header: header, payload: payload)
let signedJWT = try jwt.sign(with: JWTSigner(privateKey: privateKey))
return signedJWT
return try jwt.sign(with: JWTSigner(privateKey: privateKey))
}

@available(iOS 11.3, *)
Expand Down
6 changes: 2 additions & 4 deletions Sources/dpop/DefaultDPoPProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ class DefaultDPoPProvider: DPoPProvider {
htu: htu
)
let jwt = JWT(header: header, payload: payload)
let signedJWT = try jwt.sign(with: JWTSigner(privateKey: privateKey))
return signedJWT
return try jwt.sign(with: JWTSigner(privateKey: privateKey))
}

func computeJKT() throws -> String? {
Expand Down Expand Up @@ -75,8 +74,7 @@ class DefaultDPoPProvider: DPoPProvider {
throw NSError(domain: NSOSStatusErrorDomain, code: Int(status))
}

let privateKey = item as! SecKey
return privateKey
return item as! SecKey
}

@available(iOS 11.3, *)
Expand Down
3 changes: 1 addition & 2 deletions Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import XCTest

import AuthgearTests
import XCTest

var tests = [XCTestCaseEntry]()
tests += AuthgearTests.allTests()
Expand Down
6 changes: 4 additions & 2 deletions example/ios_example/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void
) -> Bool {
let app2appRequest = appContainer.container?.parseApp2AppAuthenticationRequest(
userActivity: userActivity)
userActivity: userActivity
)
if let app2appRequest = app2appRequest {
appContainer.pendingApp2AppRequest = app2appRequest
return true
}
if let container = appContainer.container,
container.handleApp2AppAuthenticationResult(
userActivity: userActivity) == true {
userActivity: userActivity
) == true {
return true
}
return false
Expand Down
Loading
Loading