Skip to content

Commit fdbb1d9

Browse files
authored
feat: add auth support for Github, Google, Linkedin (#307)
* feat: add auth support for Github, Google, Linkedin * add test cases * increase codecov * codecov
1 parent 3bf2471 commit fdbb1d9

31 files changed

+3662
-80
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
__Improvements__
1212
- (Breaking Change) Adds options to matchesText query constraint along with the ability to see matching score. The compiler should recommend the new score property to all ParseObjects ([#306](https://github.com/parse-community/Parse-Swift/pull/306)), thanks to [Corey Baker](https://github.com/cbaker6).
1313
- Adds withCount query ([#306](https://github.com/parse-community/Parse-Swift/pull/306)), thanks to [Corey Baker](https://github.com/cbaker6).
14+
- Adds auth support for GitHub, Google, and LinkedIn ([#307](https://github.com/parse-community/Parse-Swift/pull/307)), thanks to [Corey Baker](https://github.com/cbaker6).
1415

1516
### 2.5.1
1617
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/2.5.0...2.5.1)

ParseSwift.xcodeproj/project.pbxproj

Lines changed: 163 additions & 1 deletion
Large diffs are not rendered by default.

Sources/ParseSwift/Authentication/3rd Party/ParseApple/ParseApple+async.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public extension ParseApple {
1515
/**
1616
Login a `ParseUser` *asynchronously* using Apple authentication.
1717
- parameter user: The `user` from `ASAuthorizationAppleIDCredential`.
18-
- parameter identityToken: The `identityToken` from `ASAuthorizationAppleIDCredential`.
18+
- parameter identityToken: The **identityToken** from `ASAuthorizationAppleIDCredential`.
1919
- parameter options: A set of header options sent to the server. Defaults to an empty set.
2020
- returns: An instance of the logged in `ParseUser`.
2121
- throws: An error of type `ParseError`.
@@ -53,7 +53,7 @@ public extension ParseApple {
5353
/**
5454
Link the *current* `ParseUser` *asynchronously* using Apple authentication.
5555
- parameter user: The `user` from `ASAuthorizationAppleIDCredential`.
56-
- parameter identityToken: The `identityToken` from `ASAuthorizationAppleIDCredential`.
56+
- parameter identityToken: The **identityToken** from `ASAuthorizationAppleIDCredential`.
5757
- parameter options: A set of header options sent to the server. Defaults to an empty set.
5858
- returns: An instance of the logged in `ParseUser`.
5959
- throws: An error of type `ParseError`.

Sources/ParseSwift/Authentication/3rd Party/ParseApple/ParseApple+combine.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public extension ParseApple {
1616
/**
1717
Login a `ParseUser` *asynchronously* using Apple authentication. Publishes when complete.
1818
- parameter user: The `user` from `ASAuthorizationAppleIDCredential`.
19-
- parameter identityToken: The `identityToken` from `ASAuthorizationAppleIDCredential`.
19+
- parameter identityToken: The **identityToken** from `ASAuthorizationAppleIDCredential`.
2020
- parameter options: A set of header options sent to the server. Defaults to an empty set.
2121
- returns: A publisher that eventually produces a single value and then finishes or fails.
2222
*/
@@ -52,7 +52,7 @@ public extension ParseApple {
5252
/**
5353
Link the *current* `ParseUser` *asynchronously* using Apple authentication. Publishes when complete.
5454
- parameter user: The `user` from `ASAuthorizationAppleIDCredential`.
55-
- parameter identityToken: The `identityToken` from `ASAuthorizationAppleIDCredential`.
55+
- parameter identityToken: The **identityToken** from `ASAuthorizationAppleIDCredential`.
5656
- parameter options: A set of header options sent to the server. Defaults to an empty set.
5757
- returns: A publisher that eventually produces a single value and then finishes or fails.
5858
*/

Sources/ParseSwift/Authentication/3rd Party/ParseApple/ParseApple.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public struct ParseApple<AuthenticatedUser: ParseUser>: ParseAuthentication {
2626
/// - parameter user: Required id for the user.
2727
/// - parameter identityToken: Required identity token for the user.
2828
/// - returns: authData dictionary.
29-
/// - throws: `ParseError` if the `identityToken` can't be converted
29+
/// - throws: `ParseError` if the **identityToken** can't be converted
3030
/// to a string.
3131
func makeDictionary(user: String,
3232
identityToken: Data) throws -> [String: String] {
@@ -59,7 +59,7 @@ public extension ParseApple {
5959
/**
6060
Login a `ParseUser` *asynchronously* using Apple authentication.
6161
- parameter user: The `user` from `ASAuthorizationAppleIDCredential`.
62-
- parameter identityToken: The `identityToken` from `ASAuthorizationAppleIDCredential`.
62+
- parameter identityToken: The **identityToken** from `ASAuthorizationAppleIDCredential`.
6363
- parameter options: A set of header options sent to the server. Defaults to an empty set.
6464
- parameter callbackQueue: The queue to return to after completion. Default value of .main.
6565
- parameter completion: The block to execute.
@@ -108,7 +108,7 @@ public extension ParseApple {
108108
/**
109109
Link the *current* `ParseUser` *asynchronously* using Apple authentication.
110110
- parameter user: The `user` from `ASAuthorizationAppleIDCredential`.
111-
- parameter identityToken: The `identityToken` from `ASAuthorizationAppleIDCredential`.
111+
- parameter identityToken: The **identityToken** from `ASAuthorizationAppleIDCredential`.
112112
- parameter options: A set of header options sent to the server. Defaults to an empty set.
113113
- parameter callbackQueue: The queue to return to after completion. Default value of .main.
114114
- parameter completion: The block to execute.

Sources/ParseSwift/Authentication/3rd Party/ParseFacebook/ParseFacebook+async.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ public extension ParseFacebook {
1414

1515
/**
1616
Login a `ParseUser` *asynchronously* using Facebook authentication for limited login.
17-
- parameter userId: The `userId` from `FacebookSDK`.
18-
- parameter authenticationToken: The `authenticationToken` from `FacebookSDK`.
17+
- parameter userId: The **id** from **FacebookSDK**.
18+
- parameter authenticationToken: The `authenticationToken` from **FacebookSDK**.
1919
- parameter expiresIn: Optional expiration in seconds for Facebook login.
2020
- parameter options: A set of header options sent to the server. Defaults to an empty set.
2121
- returns: An instance of the logged in `ParseUser`.
@@ -36,8 +36,8 @@ public extension ParseFacebook {
3636

3737
/**
3838
Login a `ParseUser` *asynchronously* using Facebook authentication for graph API login.
39-
- parameter userId: The `userId` from `FacebookSDK`.
40-
- parameter accessToken: The `accessToken` from `FacebookSDK`.
39+
- parameter userId: The **id** from **FacebookSDK**.
40+
- parameter accessToken: The `accessToken` from **FacebookSDK**.
4141
- parameter expiresIn: Optional expiration in seconds for Facebook login.
4242
- parameter options: A set of header options sent to the server. Defaults to an empty set.
4343
- returns: An instance of the logged in `ParseUser`.
@@ -75,8 +75,8 @@ public extension ParseFacebook {
7575
public extension ParseFacebook {
7676
/**
7777
Link the *current* `ParseUser` *asynchronously* using Facebook authentication for limited login.
78-
- parameter userId: The `userId` from `FacebookSDK`.
79-
- parameter authenticationToken: The `authenticationToken` from `FacebookSDK`.
78+
- parameter userId: The **id** from **FacebookSDK**.
79+
- parameter authenticationToken: The `authenticationToken` from **FacebookSDK**.
8080
- parameter expiresIn: Optional expiration in seconds for Facebook login.
8181
- parameter options: A set of header options sent to the server. Defaults to an empty set.
8282
- returns: An instance of the logged in `ParseUser`.
@@ -97,8 +97,8 @@ public extension ParseFacebook {
9797

9898
/**
9999
Link the *current* `ParseUser` *asynchronously* using Facebook authentication for graph API login.
100-
- parameter userId: The `userId` from `FacebookSDK`.
101-
- parameter accessToken: The `accessToken` from `FacebookSDK`.
100+
- parameter userId: The **id** from **FacebookSDK**.
101+
- parameter accessToken: The `accessToken` from **FacebookSDK**.
102102
- parameter expiresIn: Optional expiration in seconds for Facebook login.
103103
- parameter options: A set of header options sent to the server. Defaults to an empty set.
104104
- returns: An instance of the logged in `ParseUser`.

Sources/ParseSwift/Authentication/3rd Party/ParseFacebook/ParseFacebook+combine.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ public extension ParseFacebook {
1414
// MARK: Combine
1515
/**
1616
Login a `ParseUser` *asynchronously* using Facebook authentication for limited login. Publishes when complete.
17-
- parameter userId: The `userId` from `FacebookSDK`.
18-
- parameter authenticationToken: The `authenticationToken` from `FacebookSDK`.
17+
- parameter userId: The **id** from **FacebookSDK**.
18+
- parameter authenticationToken: The `authenticationToken` from **FacebookSDK**.
1919
- parameter expiresIn: Optional expiration in seconds for Facebook login.
2020
- parameter options: A set of header options sent to the server. Defaults to an empty set.
2121
- returns: A publisher that eventually produces a single value and then finishes or fails.
@@ -35,8 +35,8 @@ public extension ParseFacebook {
3535

3636
/**
3737
Login a `ParseUser` *asynchronously* using Facebook authentication for graph API login. Publishes when complete.
38-
- parameter userId: The `userId` from `FacebookSDK`.
39-
- parameter accessToken: The `accessToken` from `FacebookSDK`.
38+
- parameter userId: The **id** from **FacebookSDK**.
39+
- parameter accessToken: The `accessToken` from **FacebookSDK**.
4040
- parameter expiresIn: Optional expiration in seconds for Facebook login.
4141
- parameter options: A set of header options sent to the server. Defaults to an empty set.
4242
- returns: A publisher that eventually produces a single value and then finishes or fails.
@@ -73,8 +73,8 @@ public extension ParseFacebook {
7373
/**
7474
Link the *current* `ParseUser` *asynchronously* using Facebook authentication for limited login.
7575
Publishes when complete.
76-
- parameter userId: The `userId` from `FacebookSDK`.
77-
- parameter authenticationToken: The `authenticationToken` from `FacebookSDK`.
76+
- parameter userId: The **id** from **FacebookSDK**.
77+
- parameter authenticationToken: The `authenticationToken` from **FacebookSDK**.
7878
- parameter expiresIn: Optional expiration in seconds for Facebook login.
7979
- parameter options: A set of header options sent to the server. Defaults to an empty set.
8080
- returns: A publisher that eventually produces a single value and then finishes or fails.
@@ -95,8 +95,8 @@ public extension ParseFacebook {
9595
/**
9696
Link the *current* `ParseUser` *asynchronously* using Facebook authentication for graph API login.
9797
Publishes when complete.
98-
- parameter userId: The `userId` from `FacebookSDK`.
99-
- parameter accessToken: The `accessToken` from `FacebookSDK`.
98+
- parameter userId: The **id** from **FacebookSDK**.
99+
- parameter accessToken: The `accessToken` from **FacebookSDK**.
100100
- parameter expiresIn: Optional expiration in seconds for Facebook login.
101101
- parameter options: A set of header options sent to the server. Defaults to an empty set.
102102
- returns: A publisher that eventually produces a single value and then finishes or fails.

Sources/ParseSwift/Authentication/3rd Party/ParseFacebook/ParseFacebook.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Foundation
1111

1212
/**
1313
Provides utility functions for working with Facebook User Authentication and `ParseUser`'s.
14-
Be sure your Parse Server is configured for [sign in with Facebook](https://docs.parseplatform.org/parse-server/guide/#configuring-parse-server-for-sign-in-with-facebook).
14+
Be sure your Parse Server is configured for [sign in with Facebook](https://docs.parseplatform.org/parse-server/guide/#facebook-authdata).
1515
For information on acquiring Facebook sign-in credentials to use with `ParseFacebook`, refer to [Facebook's Documentation](https://developers.facebook.com/docs/facebook-login/limited-login).
1616
*/
1717
public struct ParseFacebook<AuthenticatedUser: ParseUser>: ParseAuthentication {
@@ -79,8 +79,8 @@ public extension ParseFacebook {
7979

8080
/**
8181
Login a `ParseUser` *asynchronously* using Facebook authentication for limited login.
82-
- parameter userId: The `Facebook userId` from `FacebookSDK`.
83-
- parameter authenticationToken: The `authenticationToken` from `FacebookSDK`.
82+
- parameter userId: The `Facebook userId` from **FacebookSDK**.
83+
- parameter authenticationToken: The `authenticationToken` from **FacebookSDK**.
8484
- parameter expiresIn: Optional expiration in seconds for Facebook login.
8585
- parameter options: A set of header options sent to the server. Defaults to an empty set.
8686
- parameter callbackQueue: The queue to return to after completion. Default value of .main.
@@ -105,8 +105,8 @@ public extension ParseFacebook {
105105

106106
/**
107107
Login a `ParseUser` *asynchronously* using Facebook authentication for graph API login.
108-
- parameter userId: The `Facebook userId` from `FacebookSDK`.
109-
- parameter accessToken: The `accessToken` from `FacebookSDK`.
108+
- parameter userId: The `Facebook userId` from **FacebookSDK**.
109+
- parameter accessToken: The `accessToken` from **FacebookSDK**.
110110
- parameter expiresIn: Optional expiration in seconds for Facebook login.
111111
- parameter options: A set of header options sent to the server. Defaults to an empty set.
112112
- parameter callbackQueue: The queue to return to after completion. Default value of .main.
@@ -154,8 +154,8 @@ public extension ParseFacebook {
154154

155155
/**
156156
Link the *current* `ParseUser` *asynchronously* using Facebook authentication for limited login.
157-
- parameter userId: The `userId` from `FacebookSDK`.
158-
- parameter authenticationToken: The `authenticationToken` from `FacebookSDK`.
157+
- parameter userId: The **id** from **FacebookSDK**.
158+
- parameter authenticationToken: The `authenticationToken` from **FacebookSDK**.
159159
- parameter expiresIn: Optional expiration in seconds for Facebook login.
160160
- parameter options: A set of header options sent to the server. Defaults to an empty set.
161161
- parameter callbackQueue: The queue to return to after completion. Default value of .main.
@@ -180,8 +180,8 @@ public extension ParseFacebook {
180180

181181
/**
182182
Link the *current* `ParseUser` *asynchronously* using Facebook authentication for graph API login.
183-
- parameter userId: The `userId` from `FacebookSDK`.
184-
- parameter accessToken: The `accessToken` from `FacebookSDK`.
183+
- parameter userId: The **id** from **FacebookSDK**.
184+
- parameter accessToken: The `accessToken` from **FacebookSDK**.
185185
- parameter expiresIn: Optional expiration in seconds for Facebook login.
186186
- parameter options: A set of header options sent to the server. Defaults to an empty set.
187187
- parameter callbackQueue: The queue to return to after completion. Default value of .main.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
//
2+
// ParseGitHub+async.swift
3+
// ParseSwift
4+
//
5+
// Created by Corey Baker on 1/1/22.
6+
// Copyright © 2022 Parse Community. All rights reserved.
7+
//
8+
9+
#if swift(>=5.5) && canImport(_Concurrency)
10+
import Foundation
11+
12+
public extension ParseGitHub {
13+
// MARK: Async/Await
14+
15+
/**
16+
Login a `ParseUser` *asynchronously* using GitHub authentication for graph API login.
17+
- parameter id: The **id** from **GitHub**.
18+
- parameter accessToken: Required **access_token** from **GitHub**.
19+
- parameter options: A set of header options sent to the server. Defaults to an empty set.
20+
- returns: An instance of the logged in `ParseUser`.
21+
- throws: An error of type `ParseError`.
22+
*/
23+
func login(id: String,
24+
accessToken: String,
25+
options: API.Options = []) async throws -> AuthenticatedUser {
26+
try await withCheckedThrowingContinuation { continuation in
27+
self.login(id: id,
28+
accessToken: accessToken,
29+
options: options,
30+
completion: continuation.resume)
31+
}
32+
}
33+
34+
/**
35+
Login a `ParseUser` *asynchronously* using GitHub authentication for graph API login.
36+
- parameter authData: Dictionary containing key/values.
37+
- returns: An instance of the logged in `ParseUser`.
38+
- throws: An error of type `ParseError`.
39+
*/
40+
func login(authData: [String: String],
41+
options: API.Options = []) async throws -> AuthenticatedUser {
42+
try await withCheckedThrowingContinuation { continuation in
43+
self.login(authData: authData,
44+
options: options,
45+
completion: continuation.resume)
46+
}
47+
}
48+
}
49+
50+
public extension ParseGitHub {
51+
52+
/**
53+
Link the *current* `ParseUser` *asynchronously* using GitHub authentication for graph API login.
54+
- parameter id: The **id** from **GitHub**.
55+
- parameter accessToken: Required **access_token** from **GitHub**.
56+
- parameter options: A set of header options sent to the server. Defaults to an empty set.
57+
- returns: An instance of the logged in `ParseUser`.
58+
- throws: An error of type `ParseError`.
59+
*/
60+
func link(id: String,
61+
accessToken: String,
62+
options: API.Options = []) async throws -> AuthenticatedUser {
63+
try await withCheckedThrowingContinuation { continuation in
64+
self.link(id: id,
65+
accessToken: accessToken,
66+
options: options,
67+
completion: continuation.resume)
68+
}
69+
}
70+
71+
/**
72+
Link the *current* `ParseUser` *asynchronously* using GitHub authentication for graph API login.
73+
- parameter authData: Dictionary containing key/values.
74+
- parameter options: A set of header options sent to the server. Defaults to an empty set.
75+
- returns: An instance of the logged in `ParseUser`.
76+
- throws: An error of type `ParseError`.
77+
*/
78+
func link(authData: [String: String],
79+
options: API.Options = []) async throws -> AuthenticatedUser {
80+
try await withCheckedThrowingContinuation { continuation in
81+
self.link(authData: authData,
82+
options: options,
83+
completion: continuation.resume)
84+
}
85+
}
86+
}
87+
#endif

0 commit comments

Comments
 (0)