Skip to content
This repository has been archived by the owner on Aug 28, 2023. It is now read-only.

Issue #231 Support client_assertion for OIDC auth flow #275

Merged
merged 2 commits into from
Jan 6, 2017

Conversation

lovemaths
Copy link
Contributor

For hybrid/code flow, client secret or client assertion is required to redeem the authorization code for access token. This fix enables user to use client assertion.

  1. Added thumbprint and privatePEMKey options, so user can use the client assertion flow. However, client secret flow takes precedence. We will use client secret flow if clientSecret option is provided by user, regardless the values of thumbprint and privatePEMKey.
  2. Added unit tests and end to end tests for client assertion flow.

For hybrid/code flow, client secret or client assertion is required to redeem the authorization code for access token. This fix enables user to use client assertion.

1. Added `thumbprint` and `privatePEMKey` options, so user can use the client assertion flow. However, client secret flow takes precedence. We will use client secret flow if `clientSecret` option is provided by user, regardless the values of `thumbprint` and `privatePEMKey`.
2. Added unit tests and end to end tests for client assertion flow.
if (options.responseType !== 'id_token') {
if (options.isB2C && !options.clientSecret) {
// for B2C, clientSecret is required to redeem authorization code.
throw new Error('clientSecret is not provided.');
Copy link
Member

Choose a reason for hiding this comment

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

Please add context in this error message indicating that the scenario is B2C.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

post_params['client_assertion'] = assertion;
});

log.info('In _getAccessTokenBySecretOrAssertion: we created a client assertion: ' + post_params['client_assertion']);
Copy link
Member

Choose a reason for hiding this comment

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

recommend not logging the client assertion, just the thumbprint.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -144,6 +145,18 @@ var apply_test_parameters = (done) => {
hybrid_config_with_scope = JSON.parse(JSON.stringify(config_template));
hybrid_config_with_scope.scope = ['email', 'profile', 'offline_access', 'https://graph.microsoft.com/mail.read'];

// 6. Hybird flow using client assertion
hybrid_config_clientAssertion = JSON.parse(JSON.stringify(hybrid_config));
Copy link
Member

Choose a reason for hiding this comment

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

is hybrid_config variable needed? could you use config_template?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hybrid_config is needed since we also have code_config and implicit_config variables, for the three different flows.

// 4. hybrid flow using client assertion with wrong thumbprint
hybrid_config_clientAssertion_wrong_thumbprint = JSON.parse(JSON.stringify(hybrid_config));
hybrid_config_clientAssertion_wrong_thumbprint.thumbprint = 'wrongThumbprint';
hybrid_config_clientAssertion_wrong_thumbprint.privatePEMKey = test_parameters.privatePEMKey;
Copy link
Member

Choose a reason for hiding this comment

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

is there a test for an invalid 'privatePEMKey' where the key is valid, but not registered with AzureAD?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added now

hybrid_config_clientAssertion.clientSecret = null;

// 7. Code flow using client assertion
code_config_clientAssertion = JSON.parse(JSON.stringify(code_config));
Copy link
Member

Choose a reason for hiding this comment

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

is code_config variable needed? could you use config_template?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is needed. To get code_config, we make a copy of config_template, and change the responseType field to 'code'.

@brentschmaltz
Copy link
Member

:shipit:

@lovemaths lovemaths merged commit 3a55528 into dev Jan 6, 2017
@lovemaths lovemaths deleted the sijliu/assertion branch January 6, 2017 18:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants