Skip to content
Open
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
45 changes: 37 additions & 8 deletions OAuth2.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
/* Begin PBXBuildFile section */
0C2F5E5B1DE2DB8500F621E0 /* OAuth2CodeGrantAzure.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C2F5E5A1DE2DB8500F621E0 /* OAuth2CodeGrantAzure.swift */; };
19C919DD1E51CC8000BFC834 /* OAuth2CustomAuthorizer+macOS.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19C919DC1E51CC8000BFC834 /* OAuth2CustomAuthorizer+macOS.swift */; };
5EA7ED3A2E6ED86100124A26 /* Logging in Frameworks */ = {isa = PBXBuildFile; productRef = 5EA7ED392E6ED86100124A26 /* Logging */; };
5EA7ED3C2E6ED87300124A26 /* Logging in Frameworks */ = {isa = PBXBuildFile; productRef = 5EA7ED3B2E6ED87300124A26 /* Logging */; };
5EA7ED3E2E6ED87900124A26 /* Logging in Frameworks */ = {isa = PBXBuildFile; productRef = 5EA7ED3D2E6ED87900124A26 /* Logging */; };
5EA7ED402E6ED87E00124A26 /* Logging in Frameworks */ = {isa = PBXBuildFile; productRef = 5EA7ED3F2E6ED87E00124A26 /* Logging */; };
6598544E1C5B3C9500237D39 /* OAuth2Authorizer+tvOS.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6598543F1C5B3B4000237D39 /* OAuth2Authorizer+tvOS.swift */; };
6598544F1C5B3C9C00237D39 /* OAuth2Base.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEDB8640193FAB9200C4EEA1 /* OAuth2Base.swift */; };
659854501C5B3C9C00237D39 /* OAuth2Requestable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEF47D2A1B1E3FDD0057D838 /* OAuth2Requestable.swift */; };
Expand Down Expand Up @@ -118,9 +122,6 @@
EEACE1DD1A7E8DF7009BF3A7 /* extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEDB864B19421DAD00C4EEA1 /* extensions.swift */; };
EEACE1DF1A7E8FC1009BF3A7 /* OAuth2CodeGrantFacebook.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEACE1DE1A7E8FC1009BF3A7 /* OAuth2CodeGrantFacebook.swift */; };
EEACE1E01A7E8FC5009BF3A7 /* OAuth2CodeGrantFacebook.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEACE1DE1A7E8FC1009BF3A7 /* OAuth2CodeGrantFacebook.swift */; };
EEAEF10B1CDBCF28001A1C6F /* OAuth2Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEAEF10A1CDBCF28001A1C6F /* OAuth2Logger.swift */; };
EEAEF10C1CDBCF28001A1C6F /* OAuth2Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEAEF10A1CDBCF28001A1C6F /* OAuth2Logger.swift */; };
EEAEF10D1CDBCF28001A1C6F /* OAuth2Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEAEF10A1CDBCF28001A1C6F /* OAuth2Logger.swift */; };
EEB9A97C1D86C34E0022EF66 /* OAuth2Response.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEB9A97B1D86C34E0022EF66 /* OAuth2Response.swift */; };
EEB9A97D1D86C34E0022EF66 /* OAuth2Response.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEB9A97B1D86C34E0022EF66 /* OAuth2Response.swift */; };
EEB9A97E1D86C34E0022EF66 /* OAuth2Response.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEB9A97B1D86C34E0022EF66 /* OAuth2Response.swift */; };
Expand Down Expand Up @@ -239,7 +240,6 @@
EE9EBF1A1D775F74003263FC /* OAuth2Securable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OAuth2Securable.swift; sourceTree = "<group>"; };
EEAC17A01CAA69110025F84B /* CONTRIBUTORS.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = CONTRIBUTORS.md; sourceTree = "<group>"; };
EEACE1DE1A7E8FC1009BF3A7 /* OAuth2CodeGrantFacebook.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OAuth2CodeGrantFacebook.swift; sourceTree = "<group>"; };
EEAEF10A1CDBCF28001A1C6F /* OAuth2Logger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OAuth2Logger.swift; sourceTree = "<group>"; };
EEB9A97B1D86C34E0022EF66 /* OAuth2Response.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OAuth2Response.swift; sourceTree = "<group>"; };
EEB9A97F1D86CD4A0022EF66 /* OAuth2DataLoaderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OAuth2DataLoaderTests.swift; sourceTree = "<group>"; };
EEB9A9821D86D36A0022EF66 /* OAuth2RequestPerformer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OAuth2RequestPerformer.swift; sourceTree = "<group>"; };
Expand All @@ -263,6 +263,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
5EA7ED3E2E6ED87900124A26 /* Logging in Frameworks */,
871279812DB152B300A5AF72 /* SwiftKeychain in Frameworks */,
8760AE602E16C78000020465 /* Semaphore in Frameworks */,
);
Expand All @@ -272,6 +273,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
5EA7ED3C2E6ED87300124A26 /* Logging in Frameworks */,
8712797F2DB152AE00A5AF72 /* SwiftKeychain in Frameworks */,
8760AE5E2E16C77C00020465 /* Semaphore in Frameworks */,
);
Expand All @@ -281,6 +283,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
5EA7ED3A2E6ED86100124A26 /* Logging in Frameworks */,
8712797D2DB152A800A5AF72 /* SwiftKeychain in Frameworks */,
8760AE5C2E16C77700020465 /* Semaphore in Frameworks */,
);
Expand All @@ -290,6 +293,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
5EA7ED402E6ED87E00124A26 /* Logging in Frameworks */,
871279832DB152BB00A5AF72 /* SwiftKeychain in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -355,7 +359,6 @@
EEB9A9821D86D36A0022EF66 /* OAuth2RequestPerformer.swift */,
EEB9A97B1D86C34E0022EF66 /* OAuth2Response.swift */,
EE79F6591BFAA36900746243 /* OAuth2Error.swift */,
EEAEF10A1CDBCF28001A1C6F /* OAuth2Logger.swift */,
65EC05DF1C9050CB00DE9186 /* OAuth2KeychainAccount.swift */,
EE29EABB195A0DB2008882C8 /* OAuth2DebugURLSessionDelegate.swift */,
EE2983741D40BE7600933CDD /* OAuth2AuthorizerUI.swift */,
Expand Down Expand Up @@ -661,6 +664,7 @@
packageReferences = (
8712797A2DB151ED00A5AF72 /* XCRemoteSwiftPackageReference "SwiftKeychain" */,
8760AE5A2E16C5E800020465 /* XCRemoteSwiftPackageReference "Semaphore" */,
5EA7ED382E6ED86100124A26 /* XCRemoteSwiftPackageReference "swift-log" */,
);
productRefGroup = EEDB8625193FAAE500C4EEA1 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -739,7 +743,6 @@
EE9EBF151D775A21003263FC /* OAuth2DataLoader.swift in Sources */,
EE1070361E5C7A4200250586 /* OAuth2CustomAuthorizerUI.swift in Sources */,
87FABDDE2DC9F2DF00E0C67B /* OAuth2Actor.swift in Sources */,
EEAEF10D1CDBCF28001A1C6F /* OAuth2Logger.swift in Sources */,
EE9EBF1D1D775F74003263FC /* OAuth2Securable.swift in Sources */,
659854521C5B3C9C00237D39 /* OAuth2AuthConfig.swift in Sources */,
EEC49F331C9BF22400989A18 /* OAuth2AuthRequest.swift in Sources */,
Expand All @@ -754,7 +757,6 @@
buildActionMask = 2147483647;
files = (
EEACE1DD1A7E8DF7009BF3A7 /* extensions.swift in Sources */,
EEAEF10C1CDBCF28001A1C6F /* OAuth2Logger.swift in Sources */,
EE20118D1E44D0BD00913FA7 /* OAuth2DataLoaderSessionTaskDelegate.swift in Sources */,
65EC05E11C9050CB00DE9186 /* OAuth2KeychainAccount.swift in Sources */,
87FABDDF2DC9F2DF00E0C67B /* OAuth2Actor.swift in Sources */,
Expand Down Expand Up @@ -798,7 +800,6 @@
buildActionMask = 2147483647;
files = (
EEACE1DC1A7E8DF6009BF3A7 /* extensions.swift in Sources */,
EEAEF10B1CDBCF28001A1C6F /* OAuth2Logger.swift in Sources */,
65EC05E01C9050CB00DE9186 /* OAuth2KeychainAccount.swift in Sources */,
0C2F5E5B1DE2DB8500F621E0 /* OAuth2CodeGrantAzure.swift in Sources */,
DD0CCBAD1C4DC83A0044C4E3 /* OAuth2WebViewController+macOS.swift in Sources */,
Expand Down Expand Up @@ -1273,6 +1274,14 @@
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
5EA7ED382E6ED86100124A26 /* XCRemoteSwiftPackageReference "swift-log" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/apple/swift-log.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 1.6.4;
};
};
8712797A2DB151ED00A5AF72 /* XCRemoteSwiftPackageReference "SwiftKeychain" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/slidoapp/SwiftKeychain";
Expand All @@ -1292,6 +1301,26 @@
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
5EA7ED392E6ED86100124A26 /* Logging */ = {
isa = XCSwiftPackageProductDependency;
package = 5EA7ED382E6ED86100124A26 /* XCRemoteSwiftPackageReference "swift-log" */;
productName = Logging;
};
5EA7ED3B2E6ED87300124A26 /* Logging */ = {
isa = XCSwiftPackageProductDependency;
package = 5EA7ED382E6ED86100124A26 /* XCRemoteSwiftPackageReference "swift-log" */;
productName = Logging;
};
5EA7ED3D2E6ED87900124A26 /* Logging */ = {
isa = XCSwiftPackageProductDependency;
package = 5EA7ED382E6ED86100124A26 /* XCRemoteSwiftPackageReference "swift-log" */;
productName = Logging;
};
5EA7ED3F2E6ED87E00124A26 /* Logging */ = {
isa = XCSwiftPackageProductDependency;
package = 5EA7ED382E6ED86100124A26 /* XCRemoteSwiftPackageReference "swift-log" */;
productName = Logging;
};
8712797C2DB152A800A5AF72 /* SwiftKeychain */ = {
isa = XCSwiftPackageProductDependency;
package = 8712797A2DB151ED00A5AF72 /* XCRemoteSwiftPackageReference "SwiftKeychain" */;
Expand Down
11 changes: 10 additions & 1 deletion OAuth2.xcworkspace/xcshareddata/swiftpm/Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/slidoapp/SwiftKeychain.git", .upToNextMinor(from: "2.1.0")),
.package(url: "https://github.com/groue/Semaphore.git", .upToNextMinor(from: "0.1.0"))
.package(url: "https://github.com/groue/Semaphore.git", .upToNextMinor(from: "0.1.0")),
.package(url: "https://github.com/apple/swift-log.git", .upToNextMinor(from: "1.6.4"))
],
targets: [
.target(name: "OAuth2",
dependencies: ["Base", "Flows", "DataLoader"]),
.target(name: "Base", dependencies: ["SwiftKeychain", "Semaphore"]),
.target(name: "Base", dependencies: ["SwiftKeychain", "Semaphore", .product(name: "Logging", package: "swift-log")]),
.target(name: "macOS", dependencies: [.target(name: "Base")]),
.target(name: "iOS", dependencies: [.target(name: "Base")]),
.target(name: "tvOS", dependencies: [.target(name: "Base")]),
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Need to specify a separate refresh token URI? You can set the `refresh_uri` in t
Need to debug? Use a `.debug` or even a `.trace` logger:

```swift
oauth2.logger = OAuth2DebugLogger(.trace)
oauth2.logger?.logLevel = .trace
```

For more see [advanced settings](#advanced-settings) below.
Expand Down Expand Up @@ -554,6 +554,10 @@ These three steps are needed to:
2. Link the framework into your app
3. Embed the framework in your app when distributing

Swift Logging
-------------

This library uses the [Swift logging system](https://swiftpackageindex.com/apple/swift-log) for internal logging. You can adjust the log level and configure the logger as needed for your application.

License
-------
Expand Down
8 changes: 4 additions & 4 deletions Sources/Base/OAuth2AuthRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,14 @@ open class OAuth2AuthRequest {

// add to request body
if oauth2.clientConfig.secretInBody {
oauth2.logger?.debug("OAuth2", msg: "Adding “client_id” and “client_secret” to request body")
oauth2.logger?.debug("Adding “client_id” and “client_secret” to request body")
finalParams["client_id"] = clientId
finalParams["client_secret"] = secret
}

// add Authorization header (if not in body)
else {
oauth2.logger?.debug("OAuth2", msg: "Adding “Authorization” header as “Basic client-key:client-secret”")
oauth2.logger?.debug("Adding “Authorization” header as “Basic client-key:client-secret”")
let pw = "\(clientId.wwwFormURLEncodedString):\(secret.wwwFormURLEncodedString)"
if let utf8 = pw.data(using: oauth2.clientConfig.authStringEncoding) {
req.setValue("Basic \(utf8.base64EncodedString())", forHTTPHeaderField: "Authorization")
Expand All @@ -212,13 +212,13 @@ open class OAuth2AuthRequest {
// add custom headers, first from our OAuth2 instance, then our custom ones
if let headers = oauth2.authHeaders {
for (key, val) in headers {
oauth2.logger?.trace("OAuth2", msg: "Overriding “\(key)” header")
oauth2.logger?.trace("Overriding “\(key)” header")
req.setValue(val, forHTTPHeaderField: key)
}
}
if let headers = headers {
for (key, val) in headers {
oauth2.logger?.trace("OAuth2", msg: "Adding custom “\(key)” header")
oauth2.logger?.trace("Adding custom “\(key)” header")
req.setValue(val, forHTTPHeaderField: key)
}
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/Base/OAuth2Base.swift
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ open class OAuth2Base: OAuth2Securable {

override open func updateFromKeychainItems(_ items: [String: any Sendable]) {
for message in clientConfig.updateFromStorableItems(items) {
logger?.debug("OAuth2", msg: message)
logger?.debug("\(message)")
}
clientConfig.secretInBody = (clientConfig.endpointAuthMethod == OAuth2EndpointAuthMethod.clientSecretPost)
}
Expand Down Expand Up @@ -298,7 +298,7 @@ open class OAuth2Base: OAuth2Securable {
public final func didFail(with error: OAuth2Error?) {
var finalError = error
if let error = finalError {
logger?.debug("OAuth2", msg: "\(error)")
logger?.debug("\(error)")
}
else {
finalError = OAuth2Error.requestCancelled
Expand All @@ -319,7 +319,7 @@ open class OAuth2Base: OAuth2Securable {
*/
open func abortAuthorization() {
if !abortTask() {
logger?.debug("OAuth2", msg: "Aborting authorization")
logger?.debug("Aborting authorization")
didFail(with: nil)
}
}
Expand Down Expand Up @@ -472,7 +472,7 @@ open class OAuth2Base: OAuth2Securable {
guard let state = params["state"] as? String, !state.isEmpty else {
throw OAuth2Error.missingState
}
logger?.trace("OAuth2", msg: "Checking state, got “\(state)”, expecting “\(context.state)")
logger?.trace("Checking state, got “\(state)”, expecting “\(context.state)")
if !context.matchesState(state) {
throw OAuth2Error.invalidState
}
Expand Down
Loading