Skip to content

Commit 9f13287

Browse files
committed
rename and fix oauth/token test.
1 parent a22b2f9 commit 9f13287

2 files changed

Lines changed: 13 additions & 16 deletions

File tree

auth0/src/test/java/com/auth0/authentication/AuthenticationAPIClientTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,24 +1173,24 @@ public void shouldFetchProfileAfterLoginRequest() throws Exception {
11731173
}
11741174

11751175
@Test
1176-
public void shouldGetOAuthToken() throws Exception {
1176+
public void shouldGetOAuthTokens() throws Exception {
11771177
mockAPI
1178-
.willReturnAuthorizationCodeInfo()
1178+
.willReturnTokens()
11791179
.willReturnTokenInfo();
11801180

11811181
final MockBaseCallback<Credentials> callback = new MockBaseCallback<>();
1182-
client.token("code", AuthenticationAPI.CODE_VERIFIER, AuthenticationAPI.REDIRECT_URI)
1182+
client.token("code", "codeVerifier", "http://redirect.uri")
11831183
.start(callback);
11841184

11851185
final RecordedRequest request = mockAPI.takeRequest();
11861186
assertThat(request.getPath(), equalTo("/oauth/token"));
11871187

11881188
Map<String, String> body = bodyFromRequest(request);
1189-
assertThat(body, hasEntry("redirect_uri", AuthenticationAPI.REDIRECT_URI));
11901189
assertThat(body, hasEntry("grant_type", ParameterBuilder.GRANT_TYPE_AUTHORIZATION_CODE));
11911190
assertThat(body, hasEntry("client_id", CLIENT_ID));
1192-
assertThat(body, hasEntry("code_verifier", AuthenticationAPI.CODE_VERIFIER));
11931191
assertThat(body, hasEntry("code", "code"));
1192+
assertThat(body, hasEntry("code_verifier", "codeVerifier"));
1193+
assertThat(body, hasEntry("redirect_uri", "http://redirect.uri"));
11941194

11951195
assertThat(callback, hasPayloadOfType(Credentials.class));
11961196
}

auth0/src/test/java/com/auth0/util/AuthenticationAPI.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,16 @@
3030

3131
import java.io.IOException;
3232

33-
public class AuthenticationAPI {
33+
public class AuthenticationAPI {
3434

3535
public static final String REFRESH_TOKEN = "REFRESH_TOKEN";
3636
public static final String ID_TOKEN = "ID_TOKEN";
3737
public static final String ACCESS_TOKEN = "ACCESS_TOKEN";
3838
public static final String BEARER = "BEARER";
3939
public static final String GENERIC_TOKEN = "GENERIC_TOKEN";
4040
public static final String NEW_ID_TOKEN = "NEW_ID_TOKEN";
41-
public static final int EXPIRES_IN = 1234567890;
4241
public static final String TOKEN_TYPE = "TOKEN_TYPE";
43-
public static final String CODE_VERIFIER = "CODE_VERIFIER";
44-
public static final String REDIRECT_URI = "REDIRECT_URI";
42+
public static final int EXPIRES_IN = 1234567890;
4543

4644
private MockWebServer server;
4745

@@ -157,20 +155,19 @@ public AuthenticationAPI willReturnTokenInfo() {
157155
return this;
158156
}
159157

160-
public AuthenticationAPI willReturnAuthorizationCodeInfo() {
158+
public AuthenticationAPI willReturnTokens() {
161159
String json = "{\"" +
162-
"redirect_uri\": \"" + REDIRECT_URI + "\"," +
163-
"\"code_verifier\": \"" + CODE_VERIFIER + "\"," +
164-
"\"client_id\":\"U5MhUrbyQHSVWjlEqZSTCBUFABLbJAS3\"," +
165-
"\"code\": \"" + CODE_VERIFIER + "\",\n" +
166-
"\"grant_type\":\"authorization_code\"" +
160+
"access_token\": \"" + ACCESS_TOKEN + "\"," +
161+
"\"refresh_token\": \"" + REFRESH_TOKEN + "\"," +
162+
"\"id_token\":\"" + ID_TOKEN + "\"," +
163+
"\"token_type\":\"Bearer\"" +
167164
"}";
168165
server.enqueue(responseWithJSON(json, 200));
169166
return this;
170167
}
171168

172169
public AuthenticationAPI willReturnApplicationResponseWithBody(String body, int statusCode) {
173-
MockResponse response = new MockResponse()
170+
MockResponse response = new MockResponse()
174171
.setResponseCode(statusCode)
175172
.addHeader("Content-Type", "application/x-javascript")
176173
.setBody(body);

0 commit comments

Comments
 (0)