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 hasValidCredentials and clearCredentials to CredentialsManager #102

Merged
merged 4 commits into from
Jul 10, 2017

Conversation

lbalmaceda
Copy link
Contributor

No description provided.

String idToken = storage.retrieveString(KEY_ID_TOKEN);
Long expiresAt = storage.retrieveLong(KEY_EXPIRES_AT);

return !(isEmpty(accessToken) && isEmpty(idToken) || expiresAt == null || expiresAt <= getCurrentTimeInMillis() && refreshToken == null);
Copy link
Contributor

Choose a reason for hiding this comment

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

the last || and && combination needs parenthesis I think. at least to read it easier
and maybe split this in two lines, or even better, one line for each "OR" condition

Copy link
Contributor Author

Choose a reason for hiding this comment

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

parenthesis is not needed because the || separates the conditions. I will add them anyway to make it easier to read. 👍

README.md Outdated
@@ -449,6 +455,13 @@ manager.getCredentials(new BaseCallback<Credentials, CredentialsManagerException
```


5. **Clear credentials**
Whenever you need to remove the credentials from the storage and make sure that the next call to `getCredentials` fails, you must clear them from the manager:
Copy link
Contributor

Choose a reason for hiding this comment

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

this is too technical, maybe it's simpler to just say "when you want to log the user out".

and make sure that the next call to getCredentials fails

saying it like this sounds weird. my goal is not to have the call fail, that it fails is just a side effect for being logged out

verify(storage).remove("com.auth0.refresh_token");
verify(storage).remove("com.auth0.token_type");
verify(storage).remove("com.auth0.expires_at");
verify(storage).remove("com.auth0.scope");
Copy link
Contributor

Choose a reason for hiding this comment

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

just to avoid forgetting checks in the future (supposed you add a new key) you can also verify for "no more interactions" in storage


when(storage.retrieveString("com.auth0.id_token")).thenReturn(null);
when(storage.retrieveString("com.auth0.access_token")).thenReturn("accessToken");
assertTrue(manager.hasCredentials());
Copy link
Contributor

Choose a reason for hiding this comment

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

any reason for the change on the way you assert things?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you mean assertTrue(something) instead of asserThat(something, is(true))?

README.md Outdated
3. **Retrieve credentials**
Existing credentials will be returned if they are still valid, otherwise the `refresh_token` will be used to attempt to renew them. If the `expires_in` or both the `access_token` and `id_token` values are missing, the method will throw a `CredentialsManagerException`. The same will happen if the credentials have expired and there's no `refresh_token` available.
3. **Check credentials existence**
There are cases were you just want to check if a user session is still valid without the need to use the user credentials right away (i.e. to know if you should present the login screen or the main screen). You could achieve a similar result by calling `getCredentials` and checking the success/failure call, but for convenience we include a `hasCredentials` method that can know in advance if a valid token is available or if it has expired but it could be refreshed, without making an additional network call. The same rules of the `getCredentials` method apply:
Copy link
Contributor

Choose a reason for hiding this comment

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

There are cases were you just want to check if a user session is still valid without the need to use the user credentials right away

I think "without the need to use the user credentials right away" can be omitted. It's simple and the example is more than enough.

You could achieve a similar result

It's not a similar result, this is not a second option. You haven't mentioned the "better" option yet. But I think you just don't even have to mention the "previous workaround". At least not before the simpler/official way.

for convenience we include a hasCredentials method that can know in advance

that can let you know

@lbalmaceda lbalmaceda force-pushed the add-credential-manager-methods branch from c0416f2 to cfc40a3 Compare July 7, 2017 16:53
/**
* Checks if a valid pair of credentials can be obtained from this manager.
*/
public boolean hasCredentials() {
Copy link
Member

Choose a reason for hiding this comment

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

I'd mention that they are valid credentials not only he existence of one. Also I'd reflect that in the name

@hzalaz hzalaz added this to the v1-Next milestone Jul 8, 2017
@lbalmaceda lbalmaceda changed the title Add hasCredentials and clearCredentials to CredentialsManager Add hasValidCredentials and clearCredentials to CredentialsManager Jul 10, 2017
@lbalmaceda lbalmaceda merged commit 3f96344 into master Jul 10, 2017
@lbalmaceda lbalmaceda deleted the add-credential-manager-methods branch July 10, 2017 15:53
@lbalmaceda lbalmaceda modified the milestones: v1-Next, 1.9.0 Jul 10, 2017
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.

3 participants