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

Credentials fields are not guaranteed to be present #74

Merged
merged 1 commit into from
Feb 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions auth0/src/main/java/com/auth0/android/result/Credentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
package com.auth0.android.result;


import com.auth0.android.util.JsonRequired;
import android.support.annotation.Nullable;

import com.google.gson.annotations.SerializedName;

/**
Expand All @@ -34,22 +35,20 @@
* <li><i>idToken</i>: Identity Token with user information</li>
* <li><i>accessToken</i>: Access Token for Auth0 API</li>
* <li><i>refreshToken</i>: Refresh Token that can be used to request new tokens without signing in again</li>
* <li><i>type</i>: The type of the received Token.</li>
* </ul>
*/
public class Credentials {

@JsonRequired
@SerializedName("access_token")
private String accessToken;

@JsonRequired
@SerializedName("token_type")
private String type;

@SerializedName("id_token")
private String idToken;


@SerializedName("refresh_token")
private String refreshToken;

Expand All @@ -60,18 +59,42 @@ public Credentials(String idToken, String accessToken, String type, String refre
this.refreshToken = refreshToken;
}

/**
* Getter for the Identity Token with user information.
*
* @return the Identity Token.
*/
@Nullable
public String getIdToken() {
return idToken;
}

/**
* Getter for the Access Token for Auth0 API.
*
* @return the Access Token.
*/
@Nullable
public String getAccessToken() {
return accessToken;
}

/**
* Getter for the type of the received Token.
*
* @return the token type.
*/
@Nullable
public String getType() {
return type;
}

/**
* Getter for the Refresh Token that can be used to request new tokens without signing in again.
*
* @return the Refresh Token.
*/
@Nullable
public String getRefreshToken() {
return refreshToken;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public void setUp() throws Exception {
}

@Test
public void shouldFailWithEmptyJson() throws Exception {
expectedException.expect(JsonParseException.class);
public void shouldNotFailWithEmptyJson() throws Exception {
buildCredentialsFrom(json(EMPTY_OBJECT));
}

Expand All @@ -44,14 +43,12 @@ public void shouldFailWithInvalidJson() throws Exception {
}

@Test
public void shouldRequireAccessToken() throws Exception {
expectedException.expect(JsonParseException.class);
public void shouldNotRequireAccessToken() throws Exception {
buildCredentialsFrom(new StringReader("{\"token_type\": \"bearer\"}"));
}

@Test
public void shouldRequireTokenType() throws Exception {
expectedException.expect(JsonParseException.class);
public void shouldNotRequireTokenType() throws Exception {
buildCredentialsFrom(new StringReader("{\"access_token\": \"some token\"}"));
}

Expand Down