Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit 64306af

Browse files
committed
type-o fixes
1 parent d79e2a1 commit 64306af

14 files changed

Lines changed: 63 additions & 57 deletions

README.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
1+
<!-- omit in toc -->
12
# SwAuth
23

3-
SwAuth is an OAuth 2.0 HTTP request library for written in Swift iOS 15.0+, macOS 12.0+, watchOS 8.0+, and tvOS 15.0+.
4+
SwAuth is an OAuth 2.0 HTTP request library written in Swift iOS 15.0+, macOS 12.0+, watchOS 8.0+, and tvOS 15.0+.
5+
6+
- [Features](#features)
7+
- [Requirements](#requirements)
8+
- [Installation/Integration](#installationintegration)
9+
- [Basic Usage](#basic-usage)
10+
- [Contributing](#contributing)
411

512
## Features
613

7-
- [x] Usable and beautiful syntax with async/await! Say goodbye to completion handler hell!
14+
- [x] Usable and beautiful syntax with async/await! Kiss completion handler hell and the closure jungle goodbye!
815
- [x] Supports Authorization Code Grant (RFC 6749/6750), Proof Key for Code Exchange (PKCE) extension for Authorization Code Grant (RFC 7636), and the Device Authorization Grant (RFC 8628).
9-
- [x] Support for all Apple platforms.
16+
- [x] Support for all Apple device platforms.
1017
- [x] Retry errored requests.
1118
- [x] Automatically refreshes tokens.
12-
- [x] Tokens stored on Keychain, cross-site request forgery mitigation with state by default.
13-
- [x] Easily deal with JSON responses with built-in [SwiftyJSON](https://github.com/SwiftyJSON/SwiftyJSON).
19+
- [x] Tokens stored on Keychain and cross-site request forgery mitigation by default.
20+
- [x] Easily deal with JSON responses with [SwiftyJSON](https://github.com/SwiftyJSON/SwiftyJSON) built-in.
1421
- [x] Easily integrate with SwiftUI.
15-
- [x] [Complete, Meticulous, Thorough, documentation.](https://swauth.netlify.app/documentation/Swauth)
16-
- [x] Errors that are actually useful... well most of the time.
22+
- [x] [Complete, meticulous, thorough, documentation.](https://swauth.netlify.app/documentation/Swauth)
23+
- [x] Errors that are probably, maybe actually useful.
1724
- [x] Built on [SwiftNIO](https://github.com/apple/swift-nio) with [AsyncHTTPClient](https://github.com/swift-server/async-http-client).
1825
- [x] QR Code for the Device Authorization Flow (tvOS/watchOS).
1926
- [x] Sample/Example Apps.
2027

21-
## Requirments
28+
## Requirements
2229

2330
- Xcode 13+
2431
- iOS 15.0+ | macOS 12.0+ | watchOS 8.0+ | tvOS 15.0+
@@ -56,7 +63,7 @@ let keychain = Keychain(service: "com.your.bundleID",
5663
let keychain = Keychain(service: "com.your.bundleID",
5764
accessGroup: "appIdentifierPrefix.com.your.bundleID").label("Your App Name")
5865

59-
let spotify = AuthorizationCodeFlow(clientID: "YourClientID",
66+
let spotify = PKCEAuthorizationFlow(clientID: "YourClientID",
6067
authorizationEndpoint: URL(string: "https://accounts.spotify.com/authorize")!,
6168
tokenEndpoint: URL(string: "https://accounts.spotify.com/api/token")!,
6269
redirectURI: "someapp://callback",
@@ -118,7 +125,7 @@ Make your changes and submit and a PR for review!
118125

119126
Nice to have list:
120127

121-
- [ ] Include ready to go implementations of Web API's with endpoints like in the [exmaple app](https://github.com/Colaski/SwAuth/blob/main/SwAuthTestApp/SwAuthTestApp/Spotify.swift)
128+
- [ ] Include ready to go implementations of Web API's with endpoints like in the [example app](https://github.com/Colaski/SwAuth/blob/main/SwAuthTestApp/SwAuthTestApp/Spotify.swift)
122129
- Perhaps Spotify, Google, Azure/Microsoft, Github etc.
123130

124-
- [ ] OAuth1 support
131+
- [ ] OAuth 1.0 support

Sources/SwAuth/AuthorizationCodeFlow.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import enum NIOHTTP1.HTTPMethod
4343
@available(iOS 15.0, macOS 12.0, watchOS 8.0, tvOS 15.0, *)
4444
open class AuthorizationCodeFlow: Swauthable {
4545
// MARK: - Properties
46-
/// The client identifier issued by the server. Is initialzed.
46+
/// The client identifier issued by the server. Is initialized.
4747
public let clientID: String
4848
/// The client secret issued by the server. Is initialized.
4949
let clientSecret: String
@@ -146,13 +146,13 @@ open class AuthorizationCodeFlow: Swauthable {
146146
open var authHeaderTokenType: String?
147147

148148
/// Some servers may allow or want the client id and client secret to be parameters in a HTTP request's
149-
/// body instead of a Basic authorization. Set false if that is the case, otherwsie a Basic Authorization will
149+
/// body instead of a Basic authorization. Set false if that is the case, otherwise a Basic Authorization will
150150
/// be used by default.
151151
open var useBasicAuthorization = true
152152

153153
// MARK: - Methods
154154
/// Handles the callback URL from an ASWebAuthenticationSession
155-
/// and sends a HTTP request to the initalized token endpoint for the tokens.
155+
/// and sends a HTTP request to the initialized token endpoint for the tokens.
156156
///
157157
/// Tokens are saved to the Keychain instance provided by the initializer. The tokens are saved using
158158
/// the instance's client id and the string "tokens" separated by a colon as the key. For example:
@@ -209,7 +209,7 @@ open class AuthorizationCodeFlow: Swauthable {
209209

210210
Example Code:
211211
```swift
212-
// the "accessGroup" parameter is only necessary if you wish to share the keychain accross
212+
// the "accessGroup" parameter is only necessary if you wish to share the keychain across
213213
// multiple targets using a keychain sharing entitlement
214214
let keychain = Keychain(service: "your.app.bundleID", accessGroup: "appIdentifierPrefix.your.app.bundleID")
215215
.label("Your App Name")
@@ -257,7 +257,7 @@ open class AuthorizationCodeFlow: Swauthable {
257257

258258
Example Code:
259259
```swift
260-
// the "accessGroup" parameter is only necessary if you wish to share the keychain accross
260+
// the "accessGroup" parameter is only necessary if you wish to share the keychain across
261261
// multiple targets using a keychain sharing entitlement
262262
let keychain = Keychain(service: "your.app.bundleID", accessGroup: "appIdentifierPrefix.your.app.bundleID")
263263
.label("Your App Name")

Sources/SwAuth/DeviceAuthorizationFlow+DeviceAuthResponse.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ extension DeviceAuthorizationFlow {
8585
public let verificationURI: String
8686
/**
8787
The server may respond with a complete verification URI in addition to a verification URI (the verification
88-
URI combined with the user code). Following the complete verification URI alows the user to not have to type-in
88+
URI combined with the user code). Following the complete verification URI allows the user to not have to type-in
8989
the user code. Is nil if one was not provided.
9090

9191
- Important: As per RFC 8628, do not display the ``completeVerificationURI`` directly to the
@@ -155,7 +155,7 @@ extension DeviceAuthorizationFlow {
155155
}
156156

157157
// MARK: - Method
158-
/// Generates a CGImage QR code from a verificaion URL.
158+
/// Generates a CGImage QR code from a verification URL.
159159
internal func verificationQRCode() -> CGImage? {
160160
let string = completeVerificationURI != nil ? completeVerificationURI! : verificationURI
161161
return EFQRCode.generate(for: string)

Sources/SwAuth/DeviceAuthorizationFlow.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import enum NIOHTTP1.HTTPMethod
3434
authorization grant is designed for Internet-connected devices that either lack a browser to perform a
3535
user-agent-based authorization or are input constrained to the extent that requiring the user to input
3636
text in order to authenticate during the authorization flow is impractical." So, this authorization
37-
flow is particularly useful for tvOS and perhaps watchOS aswell.
37+
flow is particularly useful for tvOS and perhaps watchOS as well.
3838

3939
Conforms to the ``Swauthable`` protocol.
4040

@@ -45,18 +45,18 @@ import enum NIOHTTP1.HTTPMethod
4545
@available(iOS 15.0, macOS 12.0, watchOS 8.0, tvOS 15.0, *)
4646
open class DeviceAuthorizationFlow: Swauthable {
4747
// MARK: - Properties
48-
/// The client identifier issued by the server. Is initalized.
48+
/// The client identifier issued by the server. Is initialized.
4949
public let clientID: String
5050

51-
/// Instance of KeychainAccess. Is initalized.
51+
/// Instance of KeychainAccess. Is initialized.
5252
public let keychain: Keychain
5353

5454
/// The scopes you want your app to be authorized for, separated by spaces.
5555
open var scopes: String?
5656

5757
/// The server authorization endpoint URL. Is initialized.
5858
public let authorizationEndpoint: URL
59-
/// The body parameters for the authorizaion endpoint request. Read-only.
59+
/// The body parameters for the authorization endpoint request. Read-only.
6060
///
6161
/// Not including ``scopes`` and ``additionalAuthorizationParams``, this property is:
6262
/// ```swift
@@ -229,7 +229,7 @@ open class DeviceAuthorizationFlow: Swauthable {
229229

230230
Example Code:
231231
```swift
232-
// the "accessGroup" parameter is only necessary if you wish to share the keychain accross
232+
// the "accessGroup" parameter is only necessary if you wish to share the keychain across
233233
// multiple targets using a keychain sharing entitlement
234234
let keychain = Keychain(service: "your.app.bundleID", accessGroup: "appIdentifierPrefix.your.app.bundleID")
235235
.label("Your App Name")
@@ -264,11 +264,11 @@ open class DeviceAuthorizationFlow: Swauthable {
264264

265265
This initializer calls
266266
``DeviceAuthorizationFlow/init(clientID:authorizationEndpoint:tokenEndpoint:keychain:)``,
267-
and initiializes the scopes property.
267+
and initializes the scopes property.
268268

269269
Example Code:
270270
```swift
271-
// the "accessGroup" parameter is only necessary if you wish to share the keychain accross
271+
// the "accessGroup" parameter is only necessary if you wish to share the keychain across
272272
// multiple targets using a keychain sharing entitlement
273273
let keychain = Keychain(service: "your.app.bundleID", accessGroup: "appIdentifierPrefix.your.app.bundleID")
274274
.label("Your App Name")

Sources/SwAuth/Extensions.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ internal extension Dictionary {
6060
// MARK: - Data+jsonToDict, jsonString
6161
internal extension Data {
6262
/// JSON data as an NSString
63-
var jsonString: NSString? { // NSString is printed all nice while mormal String is not :(.
63+
var jsonString: NSString? { // NSString is printed all nice while normal String is not :(.
6464
guard let object = try? JSONSerialization.jsonObject(with: self, options: []),
6565
let data = try? JSONSerialization.data(withJSONObject: object, options: [.prettyPrinted]),
6666
let string = NSString(data: data, encoding: String.Encoding.utf8.rawValue) else { return nil }
@@ -85,7 +85,7 @@ internal extension URL {
8585
/// Returns a URL appended with query items from a dictionary. If query items couldn't be appended,
8686
/// returns the original URL.
8787
///
88-
/// The dictionary ["q":"hello"] as the function paramter would return the URL:
88+
/// The dictionary ["q":"hello"] as the function parameter would return the URL:
8989
///
9090
/// www.domain.com/search
9191
/// as

Sources/SwAuth/HTTPRequest.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public struct HTTPRequest {
6464
/// will void that default behavior. If the request has not been completed after the amount of time set by this property, it
6565
/// will terminate.
6666
///
67-
/// Suppports nanoseconds, microseconds, milliseconds, seconds, minutes, hours.
67+
/// Supports nanoseconds, microseconds, milliseconds, seconds, minutes, hours.
6868
///
6969
/// examples: `.seconds(10)`
7070
public var timeoutAfter: TimeAmount?
@@ -86,7 +86,7 @@ public struct HTTPRequest {
8686
public struct Response {
8787
/// The data from the request.
8888
public let data: Data
89-
/// Retruns a [SwiftyJSON](https://github.com/SwiftyJSON/SwiftyJSON) JSON instance
89+
/// Returns a [SwiftyJSON](https://github.com/SwiftyJSON/SwiftyJSON) JSON instance
9090
/// from the request.
9191
public func json() throws -> JSON {
9292
return try data.toSwiftyJSON()

Sources/SwAuth/PKCEAuthorizationFlow.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ open class PKCEAuthorizationFlow: Swauthable {
5656
pkce.codeChallenge
5757
}
5858

59-
/// The client identifier issued by the server. Is initialzed.
59+
/// The client identifier issued by the server. Is initialized.
6060
public let clientID: String
6161

6262
/// Instance of KeychainAccess. Is initialized.
@@ -154,7 +154,7 @@ open class PKCEAuthorizationFlow: Swauthable {
154154

155155
// MARK: - Methods
156156
/// Handles the callback URL from an ASWebAuthenticationSession
157-
/// and sends a HTTP request to the initalized token endpoint for the tokens.
157+
/// and sends a HTTP request to the initialized token endpoint for the tokens.
158158
///
159159
/// Tokens are saved to the Keychain instance provided by the initializer. The tokens are saved using
160160
/// the instance's client id and the string "tokens" separated by a colon as the key. For example:
@@ -194,7 +194,7 @@ open class PKCEAuthorizationFlow: Swauthable {
194194
// MARK: - Structs
195195
// Most of the code in this struct is derivative of:
196196
// https://bootstragram.com/blog/oauth-pkce-swift-secure-code-verifiers-and-code-challenges/
197-
/// Tthe proof keys for the Proof Key for Code Exchange (PKCE) extension to the OAuth 2.0
197+
/// The proof keys for the Proof Key for Code Exchange (PKCE) extension to the OAuth 2.0
198198
/// Authorization Code Flow according to RFC 7636.
199199
internal struct PKCE {
200200
let codeVerifier: String
@@ -241,7 +241,7 @@ open class PKCEAuthorizationFlow: Swauthable {
241241

242242
Example Code:
243243
```swift
244-
// the "accessGroup" parameter is only necessary if you wish to share the keychain accross
244+
// the "accessGroup" parameter is only necessary if you wish to share the keychain across
245245
// multiple targets using a keychain sharing entitlement
246246
let keychain = Keychain(service: "your.app.bundleID", accessGroup: "appIdentifierPrefix.your.app.bundleID")
247247
.label("Your App Name")
@@ -282,11 +282,11 @@ open class PKCEAuthorizationFlow: Swauthable {
282282

283283
This initializer calls
284284
``PKCEAuthorizationFlow/init(clientID:authorizationEndpoint:tokenEndpoint:redirectURI:keychain:)``,
285-
and initiializes the scopes property.
285+
and initializes the scopes property.
286286

287287
Example Code:
288288
```swift
289-
// the "accessGroup" parameter is only necessary if you wish to share the keychain accross
289+
// the "accessGroup" parameter is only necessary if you wish to share the keychain across
290290
// multiple targets using a keychain sharing entitlement
291291
let keychain = Keychain(service: "your.app.bundleID", accessGroup: "appIdentifierPrefix.your.app.bundleID")
292292
.label("Your App Name")

Sources/SwAuth/Response.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import Foundation
2626

2727
/// A response to be handled by a ``Swauthable/authorizationResponseHandler(for:)``.
2828
///
29-
/// A repsonse is either a URL from an ASWebAuthenticationSession or a
29+
/// A response is either a URL from an ASWebAuthenticationSession or a
3030
/// ``DeviceAuthorizationFlow/DeviceAuthResponse``
3131
/// returned from the ``DeviceAuthorizationFlow/deviceFlowAuthorizationRequest()`` method.
3232
///

Sources/SwAuth/SwAuth Documentation.docc/Choosing the right Authorization Flow.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ Thus, if you are using SwAuth to send authorized requests to your server please
1010

1111
## PKCEAuthorizationFlow
1212

13-
Much like the AuthorizationCodeFlow, the ``PKCEAuthorizationFlow`` is used for devices that are not input-constrained (like iOS, iPadOS, and macOS). Unlike the AuthorizationCodeFlow, the PKCE Authorization Code Flow is safe for use in native applications (the spec was created for such purpose). No need to provide the client secret, with PKCE (Proof Key for Code Exchange) an attacker in possesion of an intercepted Authorization Code can't exchange it for a token unless they have the on-device-cryptographically-generated code verifer.
13+
Much like the AuthorizationCodeFlow, the ``PKCEAuthorizationFlow`` is used for devices that are not input-constrained (like iOS, iPadOS, and macOS). Unlike the AuthorizationCodeFlow, the PKCE Authorization Code Flow is safe for use in native applications (the spec was created for such purpose). No need to provide the client secret, with PKCE (Proof Key for Code Exchange) an attacker in possession of an intercepted Authorization Code can't exchange it for a token unless they have the on-device-cryptographically-generated code verifier.
1414

1515
The downside is that the Proof Key for Code Exchange extension to the OAuth 2.0 Authorization Code Grant needs to be supported by the Web API you are trying to send requests to. If you own the server, great! implement [RFC 7636](https://datatracker.ietf.org/doc/html/rfc7636) and/or find a server-side framework or library that implements it ([again, here's one for Node.js](https://github.com/panva/node-oidc-provider)). Otherwise, ask the owner to implement it.
1616

1717
## DeviceAuthorizationFlow
1818

19-
The ``DeviceAuthorizationFlow`` is used for use on devices that are input-constrained (like watchOS and tvOS). If the Web API you are trying to send requests to does not support the Device Authorization Grant ask the owner. If you own the server implement it or use a server-side library/framework that supports it.
19+
The ``DeviceAuthorizationFlow`` is used for use on devices that are input-constrained (like watchOS and tvOS). If the Web API you are trying to send requests to does not support the Device Authorization Grant ask the owner. If you own the server implement it or use a server-side library/framework that supports it.

Sources/SwAuth/SwAuth Documentation.docc/DeviceAuthorizationFlow.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let googleTV = DeviceAuthorizationFlow(clientID: "YourClientID",
1414
keychain: keychain
1515
scopes: "email provider")
1616
googleTV.additionalTokenRequestParams = ["client_secret": "YourClientSecret"]
17-
googleTV.additionalRefreshTokenBodyParams = ["client_id": "YourClientID", "client_secret": "YourClientSectret"]
17+
googleTV.additionalRefreshTokenBodyParams = ["client_id": "YourClientID", "client_secret": "YourClientSecret"]
1818
```
1919

2020
Now send the authorization request and handle the response:
@@ -24,7 +24,7 @@ let deviceAuthReq = try await googleTV.deviceFlowAuthorizationRequest()
2424
try await googleTV.authorizationResponseHandler(for: deviceAuthReq)
2525
```
2626

27-
Obviously, you will need to diplay the authorization code and URL to the user. See ``DeviceAuthResponse`` for more information.
27+
Obviously, you will need to display the authorization code and URL to the user. See ``DeviceAuthResponse`` for more information.
2828

2929
Assuming no errors were thrown, you can now successfully make an authorized HTTP request to the endpoint of your choice and print the resulting JSON:
3030

0 commit comments

Comments
 (0)