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

Added support for root attributes when creating a new user #287

Merged
merged 2 commits into from
Jul 17, 2019

Conversation

cocojoe
Copy link
Member

@cocojoe cocojoe commented Jul 9, 2019

Added support for root attributes when creating a new user
Added Tests
Also fixed a warning in state string generation

Changes

Public API Change to createUser which now accepts an optional rootAttributes parameter.

     - parameter email:             email of the user to create
     - parameter username:          username of the user if the connection requires username. By default is 'nil'
     - parameter password:          password for the new user
     - parameter connection:        name where the user will be created (Database connection)
     - parameter userMetadata:      additional userMetadata parameters that will be added to the newly created user.
     - parameter rootAttributes:    root attributes that will be added to the newly created user. See https://auth0.com/docs/api/authentication#signup for supported attributes. Will not overwrite existing parameters.
     
     - returns: request that will yield a created database user (just email, username and email verified flag)
func createUser(email: String, username: String?, password: String, connection: String, userMetadata: [String: Any]?, rootAttributes: [String: Any]?)

References

https://auth0.com/docs/api/authentication#signup

Testing

Manually tested as well.

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

Checklist

@cocojoe cocojoe requested a review from a team July 9, 2019 18:27
@cocojoe cocojoe added this to the vNext milestone Jul 9, 2019
stevehobbsdev
stevehobbsdev previously approved these changes Jul 11, 2019
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.

what about the method signUp on the Authentication classes, shouldn't it also expose this functionality?

@@ -92,6 +92,11 @@ struct Auth0Authentication: Authentication {
]
payload["username"] = username
payload["user_metadata"] = userMetadata
if let rootAttributes = rootAttributes {
rootAttributes.forEach { (key, value) in
if payload[key] == nil { payload[key] = value }
Copy link
Contributor

Choose a reason for hiding this comment

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

this behavior should be clarified in the method documentation

Copy link
Member Author

@cocojoe cocojoe Jul 12, 2019

Choose a reason for hiding this comment

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

That seems fair, it was intended to stop abuse like overwriting of core params

Copy link
Contributor

Choose a reason for hiding this comment

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

That's no abuse IMHO. The user should be free to send whatever they want as "additional params". If they send something we already specify, that's their fault.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree with you in principal.

Auth0/Authentication.swift Show resolved Hide resolved

- returns: request that will yield a created database user (just email, username and email verified flag)
*/
func createUser(email: String, username: String?, password: String, connection: String, userMetadata: [String: Any]?) -> Request<DatabaseUser, AuthenticationError>
// swiftlint:disable:next function_parameter_count
func createUser(email: String, username: String?, password: String, connection: String, userMetadata: [String: Any]?, rootAttributes: [String: Any]?) -> Request<DatabaseUser, AuthenticationError>
Copy link
Contributor

Choose a reason for hiding this comment

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

protocols' methods can be changed without breaking users? this is a public one.

Choose a reason for hiding this comment

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

This looks like an optional argument, and it's placed at the end of the parameter list so I'm not sure it would be a breaking change.

Copy link
Member Author

Choose a reason for hiding this comment

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

The argument is optional so in use you don't need to specify it. However, Lucho is correct any class that implements the protocol still has to support the behaviour. As the Protocol is Public then we should try to avoid breaking it.

I'll add support for this in the Public Extension so the original method will still work out of the box as the method in the Public Extension is a fallback.

Auth0Tests/AuthenticationSpec.swift Show resolved Hide resolved
Auth0/SafariWebAuth.swift Show resolved Hide resolved
@cocojoe
Copy link
Member Author

cocojoe commented Jul 12, 2019

what about the method signUp on the Authentication classes, shouldn't it also expose this functionality?

It's a deprecated endpoint (non-oidc)

@cocojoe cocojoe merged commit 83613ed into master Jul 17, 2019
@cocojoe cocojoe mentioned this pull request Jul 17, 2019
@cocojoe cocojoe deleted the added-rootattrs-createuser-sdk-859 branch July 18, 2019 09:31
sam-w pushed a commit to LoungeBuddy/Auth0.swift that referenced this pull request Mar 11, 2020
* Added support for root attributes when creating a new user
Added Tests

* Review Tweaks
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

3 participants