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

Fix OIDC B2C problems #220

Merged
merged 6 commits into from
Oct 6, 2016
Merged

Fix OIDC B2C problems #220

merged 6 commits into from
Oct 6, 2016

Conversation

lovemaths
Copy link
Contributor

@lovemaths lovemaths commented Sep 26, 2016

(1) Rewrote the metadata loading and the configuration code. Restructured OIDCStrategy.
(2) #188 B2C mocha tests (partially done, waiting for the AAD fix of missing nonce to add test for hybrid/code flow)
(3) #165 rename 'callbackURL' and 'returnURL' to 'redirectUrl'.
(4) #189 Extensibility to allow issuer validation when going against commend end point
(5) #194 error message for 'sub' mismatch is incorrect after redeeming 'code'
(6) #218 missing email claim for B2C

(1) Rewrote the metadata loading and the configuration code. Restructured OIDCStrategy.
(2) #188 B2C mocha tests (partially done, waiting for the AAD fix of missing nonce to add test for hybrid/code flow)
(3) #165 rename 'callbackURL' and 'returnURL' to 'redirectUrl'.
(4) #189 Extensibility to allow issuer validation when going against commend end point
(5) #194 error message for 'sub' mismatch is incorrect after redeeming 'code'
(6) #218 missing email claim for B2C
@@ -69,18 +68,22 @@ const NONCE_MAX_AMOUNT = 10;
const NONCE_LIFE_TIME = 3600; // second

function makeProfileObject(src, raw) {
var emails = [];
if (src.upn)
emails = [src.upn];
Copy link
Contributor

Choose a reason for hiding this comment

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

@tushargupta51 Should we be using upn as emails?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

upn is always the email

Choose a reason for hiding this comment

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

upn is not necessarily the email of the user. It might have @ in it. I think this property should be called username instead of emails.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For AAD, upn is always in the email format like '[email protected]'

Choose a reason for hiding this comment

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

You are right. It is always in email format. But I am not sure if we can use that as email of the user. I saw you updated the code to set emails: src.emails. What is src here? json for id token? Is emails a new property?

if (src.upn)
emails = [src.upn];
else if (src.emails)
emails = src.emails;
Copy link
Contributor

@polita polita Sep 27, 2016

Choose a reason for hiding this comment

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

Is it possible to get both upn and emails back? What happens if we do? Do we ignore emails?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no. For B2C we get emails but not upn; for non B2C we get upn but no emails

Choose a reason for hiding this comment

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

I think for non B2c, we get email claim in the 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.

Confirmed with Danny, AAD won't return email claim in id_token. To get email claim, one needs to call graph api.

return self.fail('invalid nonce');
// For B2C, check the policy
if (self._options.isB2C) {
if (!jwtClaims.acr || jwtClaims.acr.length <= 6 || jwtClaims.acr.substring(0,6).toUpperCase() !== 'B2C_1_')
Copy link
Contributor

Choose a reason for hiding this comment

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

Please define the B2C_1_ string as a constant and then use value.length.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, will do it.

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

* @params {Object} req
* @params {Function} next
* @params {Function} nextt
Copy link
Contributor

@polita polita Sep 27, 2016

Choose a reason for hiding this comment

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

typo? Are we actually using this variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we used to, but not anymore, will remove the 'next'

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

}

log.info('received id_token: ', id_token);
log.info('received id_token: ', items.id_token);
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we logging the contents of the id_token? I don't think we want to do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

why not? logging is only seen by the developers, with the id_token it is much easier for them to debug issues

Copy link
Contributor

Choose a reason for hiding this comment

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

I spoke to Brent, and we assume for Wilson that the log can contain PII. This seems fine.

return self.failWithLog('In _flowInitializationHandler: missing policy in the request for B2C');
// policy is not case sensitive. AAD turns policy to lower case.
policy = req.query.p.toLowerCase();
if (!policy.startsWith('b2c_1_'))
Copy link
Contributor

Choose a reason for hiding this comment

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

Use the same constant as above.

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

* (3) Description:
* the metadata endpoint provided by the Microsoft Identity Portal that provides
* the keys and other important info at runtime. Examples:
* <1> v1 non-common endpoint
Copy link
Member

Choose a reason for hiding this comment

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

should we say: tenant endpoint

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it is already very clear here with the examples.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree with Brent. We should call this "v1 tenant-specific (not common) endpoint".

Copy link
Contributor

Choose a reason for hiding this comment

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

@lovemaths Is this still an open issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed it in the latest commit

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks.

* (3) Description:
* How you get the authorization code and tokens back
*
* - `redirectUrl` (1) Required
Copy link
Member

Choose a reason for hiding this comment

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

indented too far

Copy link
Contributor Author

Choose a reason for hiding this comment

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

modified

1. define B2C_1_ as a const
2. remove the 'next' parameters in a couple of function since it is no longer used
3. Fix a indentation problem
@polita
Copy link
Contributor

polita commented Oct 5, 2016

:shipit:

@tushargupta51
Copy link

:shipit: (I only reviewed makeProfileObject method)

@lovemaths lovemaths merged commit 1759847 into sijliu/v3.0.0 Oct 6, 2016
@lovemaths lovemaths deleted the sijliu/v3.0.0b2c branch October 6, 2016 19:49
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.

6 participants