Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add auth support for Github, Google, Linkedin #307

Merged
merged 4 commits into from
Jan 1, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
__Improvements__
- (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).
- Adds withCount query ([#306](https://github.com/parse-community/Parse-Swift/pull/306)), thanks to [Corey Baker](https://github.com/cbaker6).
- 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).

### 2.5.1
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/2.5.0...2.5.1)
Expand Down
164 changes: 163 additions & 1 deletion ParseSwift.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public extension ParseApple {
/**
Login a `ParseUser` *asynchronously* using Apple authentication.
- parameter user: The `user` from `ASAuthorizationAppleIDCredential`.
- parameter identityToken: The `identityToken` from `ASAuthorizationAppleIDCredential`.
- parameter identityToken: The **identityToken** from `ASAuthorizationAppleIDCredential`.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: An instance of the logged in `ParseUser`.
- throws: An error of type `ParseError`.
Expand Down Expand Up @@ -53,7 +53,7 @@ public extension ParseApple {
/**
Link the *current* `ParseUser` *asynchronously* using Apple authentication.
- parameter user: The `user` from `ASAuthorizationAppleIDCredential`.
- parameter identityToken: The `identityToken` from `ASAuthorizationAppleIDCredential`.
- parameter identityToken: The **identityToken** from `ASAuthorizationAppleIDCredential`.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: An instance of the logged in `ParseUser`.
- throws: An error of type `ParseError`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public extension ParseApple {
/**
Login a `ParseUser` *asynchronously* using Apple authentication. Publishes when complete.
- parameter user: The `user` from `ASAuthorizationAppleIDCredential`.
- parameter identityToken: The `identityToken` from `ASAuthorizationAppleIDCredential`.
- parameter identityToken: The **identityToken** from `ASAuthorizationAppleIDCredential`.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: A publisher that eventually produces a single value and then finishes or fails.
*/
Expand Down Expand Up @@ -52,7 +52,7 @@ public extension ParseApple {
/**
Link the *current* `ParseUser` *asynchronously* using Apple authentication. Publishes when complete.
- parameter user: The `user` from `ASAuthorizationAppleIDCredential`.
- parameter identityToken: The `identityToken` from `ASAuthorizationAppleIDCredential`.
- parameter identityToken: The **identityToken** from `ASAuthorizationAppleIDCredential`.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: A publisher that eventually produces a single value and then finishes or fails.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public struct ParseApple<AuthenticatedUser: ParseUser>: ParseAuthentication {
/// - parameter user: Required id for the user.
/// - parameter identityToken: Required identity token for the user.
/// - returns: authData dictionary.
/// - throws: `ParseError` if the `identityToken` can't be converted
/// - throws: `ParseError` if the **identityToken** can't be converted
/// to a string.
func makeDictionary(user: String,
identityToken: Data) throws -> [String: String] {
Expand Down Expand Up @@ -59,7 +59,7 @@ public extension ParseApple {
/**
Login a `ParseUser` *asynchronously* using Apple authentication.
- parameter user: The `user` from `ASAuthorizationAppleIDCredential`.
- parameter identityToken: The `identityToken` from `ASAuthorizationAppleIDCredential`.
- parameter identityToken: The **identityToken** from `ASAuthorizationAppleIDCredential`.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- parameter callbackQueue: The queue to return to after completion. Default value of .main.
- parameter completion: The block to execute.
Expand Down Expand Up @@ -108,7 +108,7 @@ public extension ParseApple {
/**
Link the *current* `ParseUser` *asynchronously* using Apple authentication.
- parameter user: The `user` from `ASAuthorizationAppleIDCredential`.
- parameter identityToken: The `identityToken` from `ASAuthorizationAppleIDCredential`.
- parameter identityToken: The **identityToken** from `ASAuthorizationAppleIDCredential`.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- parameter callbackQueue: The queue to return to after completion. Default value of .main.
- parameter completion: The block to execute.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public extension ParseFacebook {

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

/**
Login a `ParseUser` *asynchronously* using Facebook authentication for graph API login.
- parameter userId: The `userId` from `FacebookSDK`.
- parameter accessToken: The `accessToken` from `FacebookSDK`.
- parameter userId: The **id** from **FacebookSDK**.
- parameter accessToken: The `accessToken` from **FacebookSDK**.
- parameter expiresIn: Optional expiration in seconds for Facebook login.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: An instance of the logged in `ParseUser`.
Expand Down Expand Up @@ -75,8 +75,8 @@ public extension ParseFacebook {
public extension ParseFacebook {
/**
Link the *current* `ParseUser` *asynchronously* using Facebook authentication for limited login.
- parameter userId: The `userId` from `FacebookSDK`.
- parameter authenticationToken: The `authenticationToken` from `FacebookSDK`.
- parameter userId: The **id** from **FacebookSDK**.
- parameter authenticationToken: The `authenticationToken` from **FacebookSDK**.
- parameter expiresIn: Optional expiration in seconds for Facebook login.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: An instance of the logged in `ParseUser`.
Expand All @@ -97,8 +97,8 @@ public extension ParseFacebook {

/**
Link the *current* `ParseUser` *asynchronously* using Facebook authentication for graph API login.
- parameter userId: The `userId` from `FacebookSDK`.
- parameter accessToken: The `accessToken` from `FacebookSDK`.
- parameter userId: The **id** from **FacebookSDK**.
- parameter accessToken: The `accessToken` from **FacebookSDK**.
- parameter expiresIn: Optional expiration in seconds for Facebook login.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: An instance of the logged in `ParseUser`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public extension ParseFacebook {
// MARK: Combine
/**
Login a `ParseUser` *asynchronously* using Facebook authentication for limited login. Publishes when complete.
- parameter userId: The `userId` from `FacebookSDK`.
- parameter authenticationToken: The `authenticationToken` from `FacebookSDK`.
- parameter userId: The **id** from **FacebookSDK**.
- parameter authenticationToken: The `authenticationToken` from **FacebookSDK**.
- parameter expiresIn: Optional expiration in seconds for Facebook login.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: A publisher that eventually produces a single value and then finishes or fails.
Expand All @@ -35,8 +35,8 @@ public extension ParseFacebook {

/**
Login a `ParseUser` *asynchronously* using Facebook authentication for graph API login. Publishes when complete.
- parameter userId: The `userId` from `FacebookSDK`.
- parameter accessToken: The `accessToken` from `FacebookSDK`.
- parameter userId: The **id** from **FacebookSDK**.
- parameter accessToken: The `accessToken` from **FacebookSDK**.
- parameter expiresIn: Optional expiration in seconds for Facebook login.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: A publisher that eventually produces a single value and then finishes or fails.
Expand Down Expand Up @@ -73,8 +73,8 @@ public extension ParseFacebook {
/**
Link the *current* `ParseUser` *asynchronously* using Facebook authentication for limited login.
Publishes when complete.
- parameter userId: The `userId` from `FacebookSDK`.
- parameter authenticationToken: The `authenticationToken` from `FacebookSDK`.
- parameter userId: The **id** from **FacebookSDK**.
- parameter authenticationToken: The `authenticationToken` from **FacebookSDK**.
- parameter expiresIn: Optional expiration in seconds for Facebook login.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: A publisher that eventually produces a single value and then finishes or fails.
Expand All @@ -95,8 +95,8 @@ public extension ParseFacebook {
/**
Link the *current* `ParseUser` *asynchronously* using Facebook authentication for graph API login.
Publishes when complete.
- parameter userId: The `userId` from `FacebookSDK`.
- parameter accessToken: The `accessToken` from `FacebookSDK`.
- parameter userId: The **id** from **FacebookSDK**.
- parameter accessToken: The `accessToken` from **FacebookSDK**.
- parameter expiresIn: Optional expiration in seconds for Facebook login.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: A publisher that eventually produces a single value and then finishes or fails.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Foundation

/**
Provides utility functions for working with Facebook User Authentication and `ParseUser`'s.
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).
Be sure your Parse Server is configured for [sign in with Facebook](https://docs.parseplatform.org/parse-server/guide/#facebook-authdata).
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).
*/
public struct ParseFacebook<AuthenticatedUser: ParseUser>: ParseAuthentication {
Expand Down Expand Up @@ -79,8 +79,8 @@ public extension ParseFacebook {

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

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

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

/**
Link the *current* `ParseUser` *asynchronously* using Facebook authentication for graph API login.
- parameter userId: The `userId` from `FacebookSDK`.
- parameter accessToken: The `accessToken` from `FacebookSDK`.
- parameter userId: The **id** from **FacebookSDK**.
- parameter accessToken: The `accessToken` from **FacebookSDK**.
- parameter expiresIn: Optional expiration in seconds for Facebook login.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- parameter callbackQueue: The queue to return to after completion. Default value of .main.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
//
// ParseGitHub+async.swift
// ParseSwift
//
// Created by Corey Baker on 1/1/22.
// Copyright © 2022 Parse Community. All rights reserved.
//

#if swift(>=5.5) && canImport(_Concurrency)
import Foundation

public extension ParseGitHub {
// MARK: Async/Await

/**
Login a `ParseUser` *asynchronously* using GitHub authentication for graph API login.
- parameter id: The **id** from **GitHub**.
- parameter accessToken: Required **access_token** from **GitHub**.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: An instance of the logged in `ParseUser`.
- throws: An error of type `ParseError`.
*/
func login(id: String,
accessToken: String,
options: API.Options = []) async throws -> AuthenticatedUser {
try await withCheckedThrowingContinuation { continuation in
self.login(id: id,
accessToken: accessToken,
options: options,
completion: continuation.resume)
}
}

/**
Login a `ParseUser` *asynchronously* using GitHub authentication for graph API login.
- parameter authData: Dictionary containing key/values.
- returns: An instance of the logged in `ParseUser`.
- throws: An error of type `ParseError`.
*/
func login(authData: [String: String],
options: API.Options = []) async throws -> AuthenticatedUser {
try await withCheckedThrowingContinuation { continuation in
self.login(authData: authData,
options: options,
completion: continuation.resume)
}
}
}

public extension ParseGitHub {

/**
Link the *current* `ParseUser` *asynchronously* using GitHub authentication for graph API login.
- parameter id: The **id** from **GitHub**.
- parameter accessToken: Required **access_token** from **GitHub**.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: An instance of the logged in `ParseUser`.
- throws: An error of type `ParseError`.
*/
func link(id: String,
accessToken: String,
options: API.Options = []) async throws -> AuthenticatedUser {
try await withCheckedThrowingContinuation { continuation in
self.link(id: id,
accessToken: accessToken,
options: options,
completion: continuation.resume)
}
}

/**
Link the *current* `ParseUser` *asynchronously* using GitHub authentication for graph API login.
- parameter authData: Dictionary containing key/values.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: An instance of the logged in `ParseUser`.
- throws: An error of type `ParseError`.
*/
func link(authData: [String: String],
options: API.Options = []) async throws -> AuthenticatedUser {
try await withCheckedThrowingContinuation { continuation in
self.link(authData: authData,
options: options,
completion: continuation.resume)
}
}
}
#endif
Loading