Skip to content

Anonymous and Apple Login #53

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

Merged
merged 27 commits into from
Jan 18, 2021
Merged

Anonymous and Apple Login #53

merged 27 commits into from
Jan 18, 2021

Conversation

cbaker6
Copy link
Contributor

@cbaker6 cbaker6 commented Jan 15, 2021

This PR adds 3rd party login ability via the ParseAuthenticatable protocol.

  • Add ParseAnonymous and ParseApple login
  • Add ParseAuthenticatable protocol for implementation by developers. Example: Facebook, Twitter, etc. should conform to protocol and PR's can be submitted to add them. The dependency of the the respective framework, i.e. import FBSDKCoreKit shouldn't be part of the PR (this should be done by the developer in their respective apps). Instead the implementation should just ensure the necessary AuthenticationKeys are captured to properly authenticate the respective framework with a Parse Server. An example of this is ParseApple.swift. As a starting point for those who want to add more 3rd party methods, I recommend copying ParseApple.swift and modifying AuthenticationKeys and helper methods. All of the Parse server-side 3rd party supported authentication methods are here along with their respective documentation.
  • Add ParseSession protocol
  • Add documentation
  • Add test cases
  • Add playground examples

Usage (same can be done for "apple", just need to pass in apple credentials to login):

// Anonymous asynchronous login

//Assuming you define the ParseUser
struct User: ParseUser {
    //: These are required for ParseObject
    var objectId: String?
    var createdAt: Date?
    var updatedAt: Date?
    var ACL: ParseACL?

    //: These are required for ParseUser
    var username: String?
    var email: String?
    var password: String?
    var authData: [String: [String: String]?]?

    //: Your custom keys
    var customKey: String?
}

// You can log the User in using:
User.anonymous.login { result in
    switch result {
    case .success:
        print("Successfully logged in \(User.current)")
    case .failure(let error):
        print("Error logging in: \(error)")
    }
}

@cbaker6 cbaker6 marked this pull request as draft January 15, 2021 05:26
@codecov
Copy link

codecov bot commented Jan 15, 2021

Codecov Report

Merging #53 (5e8ac47) into main (84f9231) will increase coverage by 0.06%.
The diff coverage is 77.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #53      +/-   ##
==========================================
+ Coverage   76.22%   76.28%   +0.06%     
==========================================
  Files          42       46       +4     
  Lines        3886     4170     +284     
==========================================
+ Hits         2962     3181     +219     
- Misses        924      989      +65     
Impacted Files Coverage Δ
Sources/ParseSwift/API/Responses.swift 67.39% <ø> (ø)
Sources/ParseSwift/Internal/ParseHash.swift 94.11% <ø> (ø)
Sources/ParseSwift/Storage/KeychainStore.swift 97.75% <ø> (ø)
Sources/ParseSwift/Objects/ParseUser.swift 74.77% <70.40%> (-0.91%) ⬇️
...uthentication/Protocols/ParseAuthenticatable.swift 72.63% <72.63%> (ø)
...rseSwift/Authentication/3rd Party/ParseApple.swift 78.84% <78.84%> (ø)
...Swift/Authentication/Internal/ParseAnonymous.swift 86.95% <86.95%> (ø)
Sources/ParseSwift/Objects/ParseInstallation.swift 82.18% <100.00%> (+0.57%) ⬆️
Sources/ParseSwift/Objects/ParseSession.swift 100.00% <100.00%> (ø)
Sources/ParseSwift/Protocols/Objectable.swift 83.33% <100.00%> (+2.56%) ⬆️
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 84f9231...5e8ac47. Read the comment docs.

@cbaker6
Copy link
Contributor Author

cbaker6 commented Jan 16, 2021

@TomWFox can you look over the docs when you get a chance? I'm pretty much done with them and I don't think I need to a add anymore methods to the login protocols

@cbaker6
Copy link
Contributor Author

cbaker6 commented Jan 16, 2021

@TomWFox we should probably add an improved version of my second bullet point above to the contributors guide (and maybe a snippet to the readme?):

Add ParseAuthenticatable protocol for implementation by developers. Example: Facebook, Twitter, etc. should conform to protocol and PR's can be submitted to add them. The dependency of the the respective framework, i.e. import FBSDKCoreKit shouldn't be part of the PR (this should be done by the developer in their respective apps). Instead the implementation should just ensure the necessary AuthenticationKeys are captured to properly authenticate the respective framework with a Parse Server. An example of this is ParseApple.swift. As a starting point for those who want to add more 3rd party methods, I recommend copying ParseApple.swift and modifying AuthenticationKeys and helper methods. All of the Parse server-side 3rd party supported authentication methods are here along with their respective documentation.

I can see a few questions/issues occurring frequently:

  1. Can support be added for a "specific" authentication type? (Yes, following the directions above, developers are encouraged to submit PR's and have a blueprint on how to make a new one).
  2. This is different from the objc-c SDK, can we get PFFacebookUtils and PFFacebookUtils? (Not exactly, the dependency won't be added, but developers are encouraged to create and conform to ParseAuthenticatable

I think the method above we have setup for adding support for basically any authentication the server supports leads to easier maintainability. Plus, this allows users the flexibility of using any version of their authentication framework they want, they simply just need to provide the minimum keys.

@cbaker6 cbaker6 marked this pull request as ready for review January 17, 2021 06:36
Copy link
Contributor

@TomWFox TomWFox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly minor changes with one potential issue.

Getting closer to 1.0!

var user: SessionUser { get }

/// Whether the session is restricted.
var restricted: Bool { get }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be an issue, see parse-community/parse-server#6612

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I think making it "optional" should make it backwards/forwards compatible with Parse Server. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can also remove it, developers just won't be able to see it in their Swift apps because it's never decoded

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only potential problem I see with removing is it will show in their Parse Dashboard, but not on their swift apps...

Copy link
Contributor

@TomWFox TomWFox Jan 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making it optional seems like an acceptable option. I wonder whether the comment should be changed to say that the feature isn't implemented server side and/or link to the #6612

@cbaker6
Copy link
Contributor Author

cbaker6 commented Jan 18, 2021

Guessing at the issue with jazzy docs.

I believe GitHub Actions may have recently bumped the default Xcode to 12.3 and I "think" jazzy and it's dependencies aren't playing nice. It looks like the docs are building fine with 12.2, so docs can stay on that version for now, while the rest of the builds continue on the latest Xcode.

@cbaker6 cbaker6 merged commit 5d15b43 into main Jan 18, 2021
@cbaker6 cbaker6 deleted the login branch January 18, 2021 13:40
@TomWFox
Copy link
Contributor

TomWFox commented Jan 18, 2021

@TomWFox we should probably add an improved version of my second bullet point above to the contributors guide (and maybe a snippet to the readme?):

I think adding to the contributors guide would be a good idea, not sure about the readme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants