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

Use JWT to authenticate /api/device-accounts [SDK-2561] #95

Merged
merged 4 commits into from
May 26, 2021

Conversation

lbalmaceda
Copy link
Contributor

Description

The authentication of the /api/device-accounts endpoint was using an opaque token, returned by the server upon account enrollment. In some cases, previously enrolled accounts might not be able to un-enroll the device.

This PR moves the authentication to use a JWT, since the server also supports it. There are no breaking changes. The old method is still available and functional.

Depends on #94

Resources

See SDK-2561

@@ -86,7 +86,7 @@
@NonNull
public GuardianAPIRequest<Void> delete(@NonNull Enrollment enrollment) {
return client
.device(enrollment.getId(), enrollment.getDeviceToken())
.device(enrollment.getId(), enrollment.getUserId(), enrollment.getSigningKey())
Copy link
Member

Choose a reason for hiding this comment

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

Minor: why not send the whole enrollment?? since all parameters are string sending the enrollment prevents mixing them up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would be simpler but the way the SDK is structured today is sticking to the principle of least knowledge. In this particular case, that means that the Guardian API Client class doesn't have to know anything about the Enrollment class.

Copy link
Member

@joseluisdiaz joseluisdiaz May 21, 2021

Choose a reason for hiding this comment

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

I don't think that this applies here. We are using a deconstructed enrollment instead of using the actual data object, in terms of what enrollment is about this is a big chunk of what it is.
I guess that the tradeoff here how strong use of the java type system we want to do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@joseluisdiaz How I see this SDK, has two main classes for interacting with the API.

  • The raw/base API client, called GuardianAPIClient which only takes Strings and Private Keys (JDK classes) and makes the requests. Source here.
  • The wrapper, called Guardian, documented as the entry point for consumption of this SDK in the readme. This one takes DTOs, as you suggest above. Source here.

The method signature under discussion here belongs to the GuardianAPIClient class. I'm saying that the class, to be consistent with what's already there, should keep accepting strings instead of being passed the Enrollment instance. Moreover, from that instance, we only require 3 properties of the almost 10 defined. IMHO passing the entire object just to pick these 3 properties is overkill.

In the end, this is not different from how it's implemented in the Swift SDK. If you still think this implementation should be changed, please let me know what changes you want and I'll make them.

Copy link
Member

Choose a reason for hiding this comment

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

I see your point. I'm concerted about who would create the token actually. This seems to be a good enough approach.

@@ -86,7 +86,7 @@
@NonNull
public GuardianAPIRequest<Void> delete(@NonNull Enrollment enrollment) {
return client
.device(enrollment.getId(), enrollment.getDeviceToken())
.device(enrollment.getId(), enrollment.getUserId(), enrollment.getSigningKey())
Copy link
Member

Choose a reason for hiding this comment

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

I see your point. I'm concerted about who would create the token actually. This seems to be a good enough approach.

@joseluisdiaz joseluisdiaz merged commit b8a67e4 into master May 26, 2021
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.

2 participants