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

Add support for extended profile using SIWA token exchange #322

Merged
merged 6 commits into from
Nov 13, 2019

Conversation

asmclean
Copy link
Contributor

@asmclean asmclean commented Nov 11, 2019

Changes

Add support for getting name properties from the fullName property in the credential when using Sign In with Apple and token exchange. This will extract and send only values for the first and last name, similar to what's provided in the user parameter by the SIWA for websites.

References

Testing

Please describe how this can be tested by reviewers. Be specific about anything not tested and reasons why. If this library has unit and/or integration testing, tests should be added for new functionality and existing tests should complete without errors.

  • This change adds unit test coverage
  • This change has been tested on the latest version of the platform/language or why not

Checklist

Copy link
Contributor

@lbalmaceda lbalmaceda left a comment

Choose a reason for hiding this comment

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

This is a particular use case / scenario. I don't think the mapping of user object values is responsibility of the Authentication#tokenExchange method. cc @cocojoe

@cocojoe
Copy link
Member

cocojoe commented Nov 11, 2019

Agreed it's not the responsibility of the core tokenExchange method. However, is fine to happen inside the apple specific wrapper of this method.

@@ -911,21 +911,38 @@ public extension Authentication {
```
Auth0
.authentication(clientId: clientId, domain: "samples.auth0.com")
.tokenExchange(withAppleAuthorizationCode: authCode, scope: "openid profile offline_access", audience: "https://myapi.com/api)
.tokenExchange(withAppleAuthorizationCode: authCode, fullName: credentials.fullName, scope: "openid profile offline_access", audience: "https://myapi.com/api)
Copy link
Member

Choose a reason for hiding this comment

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

please change parm order to match the method

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -215,33 +215,40 @@ class AuthenticationSpec: QuickSpec {
}

}

Copy link
Member

Choose a reason for hiding this comment

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

What reformatting did you apply to this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure: I based this off of a spike that appears to have already included the whitespace changes. I've reverted them, but let me know if anything still looks off.

@@ -1,4 +1,4 @@
github "AliSoftware/OHHTTPStubs" "8.0.0"
github "Quick/Nimble" "v8.0.2"
github "Quick/Quick" "v2.1.0"
github "Quick/Nimble" "v8.0.4"
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer deps are updated in a separate PR. However, I'm okay with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was unintentional on my part, so I removed this change.

@@ -283,7 +290,22 @@ class AuthenticationSpec: QuickSpec {
}
}
}


it("should exchange apple auth code for credentials with fullName") {
Copy link
Member

Choose a reason for hiding this comment

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

are there any cases it will fail e.g. if first name is missing or last name is missing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, there are not. The values can be missing or null and it won't cause any issues. Now, I've filtered them out if there is no value.

"subject_token": authCode,
"subject_token_type": "http://auth0.com/oauth/token-type/apple-authz-code",
"scope": scope ?? "openid profile offline_access" ]
if fullName != nil {
Copy link
Member

Choose a reason for hiding this comment

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

You can tweak this a little

 if let fullName = fullName,
            let jsonData = try? String(

This also lets you remove the optionals in the JSON Object.

if fullName != nil {
if let jsonData = try? String(
data: JSONSerialization.data(
withJSONObject: [
Copy link
Member

Choose a reason for hiding this comment

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

Just to check the endpoint is fine to accept null values?

{\"lastName\":\"Walsh\",\"firstName\":null}}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, null values are okay.

@cocojoe
Copy link
Member

cocojoe commented Nov 12, 2019

@Widcket can you take a look as well, please

@cocojoe cocojoe requested a review from Widcket November 12, 2019 14:16
}
it("should exchange apple auth code for credentials with fullName") {
var fullName = PersonNameComponents()
fullName.givenName = "John"
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please add test cases for when the name and/or surname are nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added.

@crs2020
Copy link

crs2020 commented Nov 13, 2019 via email

@cocojoe cocojoe added this to the vNext milestone Nov 13, 2019
@cocojoe
Copy link
Member

cocojoe commented Nov 13, 2019

@asmclean Please can you rebase against master and I'll approve this. Thanks

@cocojoe
Copy link
Member

cocojoe commented Nov 13, 2019

Never mind I thought update was blocked, I should be good to approve in 5 mins 😄

@cocojoe cocojoe self-requested a review November 13, 2019 13:20
@cocojoe cocojoe merged commit 5e6a256 into auth0:master Nov 13, 2019
@cocojoe cocojoe mentioned this pull request Nov 14, 2019
sam-w pushed a commit to LoungeBuddy/Auth0.swift that referenced this pull request Mar 11, 2020
* Add support for extended profile using SIWA token exchange

* Fix indenting/whitespace

* Revert accidental Cartfile.resolved changes

* Reorder SIWA parameters, and stop sending missing values

* Expand test cases for SIWA
sam-w added a commit to LoungeBuddy/Auth0.swift that referenced this pull request Mar 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants