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

Improve OIDC compliance #265

Merged
merged 12 commits into from
Dec 5, 2019
Merged

Improve OIDC compliance #265

merged 12 commits into from
Dec 5, 2019

Conversation

lbalmaceda
Copy link
Contributor

@lbalmaceda lbalmaceda commented Nov 28, 2019

Changes

This update improves the SDK support for OpenID Connect. In particular, it modifies the sign-in verification phase by substituting backchannel based checks with id_token validation where possible.

Testing

This PR contains some unit tests and integration tests to prove the logic is in place for the different authentication scenarios. Additional unit tests on a separate PR will complement the token verification logic.

  • This change adds unit test coverage

  • This change adds integration test coverage

  • This change has been tested on the latest version of the platform/language or why not

Checklist

@lbalmaceda lbalmaceda modified the milestone: v1-Next Nov 28, 2019
@lbalmaceda lbalmaceda marked this pull request as ready for review November 29, 2019 20:24
@lbalmaceda lbalmaceda requested a review from a team November 29, 2019 20:24
@@ -1,16 +0,0 @@
{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed to rsa_jwks.json


import java.util.concurrent.Callable;

public class MockAuthCallback implements AuthCallback {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

belongs to the test folder. Helps assert async results

import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;

public class AuthCallbackMatcher extends BaseMatcher<AuthCallback> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

belongs to the test folder. Helps assert async results

"343064304897328574182258821353161480771090757577522755330350956839942443917109665602066633259326057104246834759269337437620283600011255" +
"336891753201992873507788546321379785324808697815139356191481700515096717744643081207558743005545844515461091232322385145532862505800570" +
"17053908908888974416937916517307412534155165744508160026990874221314025481541880285443289277406354687335857437573080004037";
private static final String EXPECTED_RSA_MODULUS = "2327856100899355911632462598898247024131242" +
Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated to match the new RSA keys for the test resources

assertThat(merged.getType(), is(codeCredentials.getType()));
assertThat(merged.getRefreshToken(), is(codeCredentials.getRefreshToken()));
assertThat(merged.getExpiresIn(), is(codeCredentials.getExpiresIn()));
Credentials frontChannelCredentials = new Credentials("urlId", "urlAccess", "urlType", null, expiresAt, "urlScope");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

basically changed the logic so the preferred credentials are:

  • id token from the front channel, when available
  • remaining things from the back channel

@@ -128,40 +136,115 @@ boolean resume(AuthorizeResult result) {
try {
assertNoError(values.get(KEY_ERROR), values.get(KEY_ERROR_DESCRIPTION));
assertValidState(parameters.get(KEY_STATE), values.get(KEY_STATE));
if (parameters.containsKey(KEY_RESPONSE_TYPE) && parameters.get(KEY_RESPONSE_TYPE).contains(RESPONSE_TYPE_ID_TOKEN)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

nonce check moved into ID token verification logic

final Credentials frontChannelCredentials = new Credentials(values.get(KEY_ID_TOKEN), values.get(KEY_ACCESS_TOKEN), values.get(KEY_TOKEN_TYPE), values.get(KEY_REFRESH_TOKEN), expiresAt, values.get(KEY_SCOPE));
boolean frontChannelIdTokenExpected = parameters.containsKey(KEY_RESPONSE_TYPE) && parameters.get(KEY_RESPONSE_TYPE).contains(RESPONSE_TYPE_ID_TOKEN);

if (frontChannelIdTokenExpected) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

always verify the front-channel ID token first, if present. Also, prefer this one over the one received on the back channel (if there is one)

/**
* Token signature verifier for HS256 algorithms.
*/
class SymmetricSignatureVerifier extends SignatureVerifier {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Kept for similarity across implementations. But could remove this class if the main class is declared non-abstract and already implements "doing nothing". Asymmetric could subclass it and implement the new behavior, like today.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest omitting it. Creates a bit of confusion having it (IMHO)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@damieng what's your take here? I know for .net you've added a NoSignatureVerifier that extends/implements SignatureVerifier. Should we keep this but rename it as yours, or remove it?


@Test
public void shouldHaveValidNonce() {
OAuthManager.assertValidNonce("1234567890", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJub25jZSI6IjEyMzQ1Njc4OTAifQ.oUb6xFIEPJQrFbel_Js4SaOwpFfM_kxHxI7xDOHgghk");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This static method was removed. But the scenario is covered in WebAuthProviderTest

@joshcanhelp joshcanhelp requested review from joshcanhelp and removed request for a team December 2, 2019 19:48
Copy link
Contributor

@joshcanhelp joshcanhelp left a comment

Choose a reason for hiding this comment

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

A few questions/comments.

My main concern with this PR is all the extra work done in the callback. Is all that necessary to add ID token validation? Particularly when we really should be pushing developers towards response_type=code here. Feels like a lot of work for situations that we should, at some point, disable.

auth0/src/test/resources/rsa_private.pem Show resolved Hide resolved
auth0/src/test/resources/rsa_jwks.json Show resolved Hide resolved
/**
* Token signature verifier for HS256 algorithms.
*/
class SymmetricSignatureVerifier extends SignatureVerifier {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest omitting it. Creates a bit of confusion having it (IMHO)

joshcanhelp
joshcanhelp previously approved these changes Dec 3, 2019
Copy link
Contributor

@joshcanhelp joshcanhelp left a comment

Choose a reason for hiding this comment

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

🎉

@lbalmaceda lbalmaceda merged commit df07ce2 into master Dec 5, 2019
@lbalmaceda lbalmaceda deleted the oidc-compliance branch December 5, 2019 14:16
@lbalmaceda lbalmaceda added this to the v1-Next milestone Dec 5, 2019
@lbalmaceda lbalmaceda modified the milestones: v1-Next, 1.20.0 Dec 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants