Skip to content

Commit

Permalink
only send audience in webauth if OIDC is true
Browse files Browse the repository at this point in the history
  • Loading branch information
lbalmaceda committed Jan 2, 2017
1 parent 8b80f6e commit 45dfaee
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/src/main/java/com/auth0/android/lock/WebProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void start(Activity activity, String connection, AuthCallback callback, i
builder.withScope(scope);
}
final String audience = options.getAudience();
if (audience != null) {
if (audience != null && options.getAccount().isOIDCConformant()) {
builder.withAudience(audience);
}
builder.start(activity, callback, requestCode);
Expand Down
35 changes: 31 additions & 4 deletions lib/src/test/java/com/auth0/android/lock/WebProviderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,37 @@ public void shouldStart() throws Exception {
webProvider.start(activity, "my-connection", callback, 123);
}

@Test
public void shouldStartWithCustomAudience() throws Exception {
Auth0 account = new Auth0("clientId", "domain.auth0.com");
account.setOIDCConformant(true);
Options options = new Options();
options.setAccount(account);

options.setUseBrowser(true);
options.withAudience("https://me.auth0.com/myapi");

AuthCallback callback = mock(AuthCallback.class);
WebProvider webProvider = new WebProvider(options);
Activity activity = spy(Robolectric.buildActivity(Activity.class)
.create()
.start()
.resume()
.get());

webProvider.start(activity, "my-connection", callback, 123);
ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
verify(activity).startActivity(intentCaptor.capture());

Intent intent = intentCaptor.getValue();
assertThat(intent, is(notNullValue()));
assertThat(intent.getData(), hasHost("domain.auth0.com"));
assertThat(intent.getData(), hasParamWithValue("client_id", "clientId"));
assertThat(intent.getData(), hasParamWithValue("connection", "my-connection"));
assertThat(intent.getData(), hasParamWithValue("audience", "https://me.auth0.com/myapi"));
assertThat(intent, hasAction(Intent.ACTION_VIEW));
}

@Test
public void shouldStartBrowserWithOptions() throws Exception {
Auth0 account = new Auth0("clientId", "domain.auth0.com");
Expand All @@ -66,7 +97,6 @@ public void shouldStartBrowserWithOptions() throws Exception {
options.withScope("email profile photos");
options.withConnectionScope("my-connection", "the connection scope");
options.setUseBrowser(true);
options.withAudience("https://me.auth0.com/myapi");

AuthCallback callback = mock(AuthCallback.class);
WebProvider webProvider = new WebProvider(options);
Expand All @@ -89,7 +119,6 @@ public void shouldStartBrowserWithOptions() throws Exception {
assertThat(intent.getData(), hasParamWithValue("custom-param-2", "value-2"));
assertThat(intent.getData(), hasParamWithValue("scope", "email profile photos"));
assertThat(intent.getData(), hasParamWithValue("connection_scope", "the connection scope"));
assertThat(intent.getData(), hasParamWithValue("audience", "https://me.auth0.com/myapi"));
assertThat(intent, hasAction(Intent.ACTION_VIEW));
}

Expand All @@ -106,7 +135,6 @@ public void shouldStartWebViewWithOptions() throws Exception {
options.withScope("email profile photos");
options.withConnectionScope("my-connection", "the connection scope");
options.setUseBrowser(false);
options.withAudience("https://me.auth0.com/myapi");

AuthCallback callback = mock(AuthCallback.class);
WebProvider webProvider = new WebProvider(options);
Expand All @@ -129,7 +157,6 @@ public void shouldStartWebViewWithOptions() throws Exception {
assertThat(intent.getData(), hasParamWithValue("custom-param-2", "value-2"));
assertThat(intent.getData(), hasParamWithValue("scope", "email profile photos"));
assertThat(intent.getData(), hasParamWithValue("connection_scope", "the connection scope"));
assertThat(intent.getData(), hasParamWithValue("audience", "https://me.auth0.com/myapi"));
assertThat(intent, hasComponent(WebAuthActivity.class.getName()));
}

Expand Down

0 comments on commit 45dfaee

Please sign in to comment.