Invalid Issuer when using Azure AD common endpoint
When authenticating via Azure AD using the multi-tenant endpoint at: https://login.microsoftonline.com/common/
tokens are returned with a tenant specific issuer:
https://sts.windows.net/{some-guid-signifying-the-azure-ad-tenantId}/
The metadata specifies the issuer as:
issuer=https://sts.windows.net/{tenantid}/
Of course this fails validation in ResponseValidator.js since the strings don't match.
In server side code we'd handle this by disabling issuer validation or adding a function to override the default comparison. Is it worth considering a similar mechanism here?
The spec says that issuer validation is mandatory. Microsoft doesn't follow the spec there too :/
I have a look at this at the end of the month -- I'm busy until then.
Did you ever come up with a workaround for this?
Yes, I added an optional delegate to allow user defined validation - https://github.com/IdentityModel/oidc-client-js/pull/626
Ah, sorry -- I totally missed the link above for that. I'll have a look and think about that... what's an example of what your callback looks like?
What I'm trying to determine is when in your user's login workflow would you determine the right value? I guess since you don't know it before they go to the common endpoint, you'd only know it after the fact during response processing.
The reason I'm going down this path is that I think I'd like to possibly make the setting less of the focus and instead something at processing time the right place for this.
Sure, I added an example to the PR. It's basically a function that returns a boolean that indicates whether returned issuer is valid
So having looked at the code again, I think the natural way (given how this all was designed a while ago) is that you should be able to replace the ResponseValidatorCtor on the OidcClientSettings. So perhaps derive from the existing one (ResponseValidator) and build your own that overdies the getIssuer API.
IOW, no changes needed to the existing code since it seems that it can support what you're looking for.
Hi @brockallen Is it possible for you to elaborate a bit more on the idea of extending ResponseValidator for achieving this. Maybe with a small example?
@chaholl did you get it working the way @brockallen mentioned 'coz I couldn't yet.
@tipsanemonk Nah, I had a look at the code and couldn't see an easy way to do without a whole load of unnecessary overhead. I'm using my fork with the delegate instead at the moment. #626
@chaholl I see, anyways thank you :- )
@chaholl did you publish your fork on npm ? is it useable by others ? thanks in advance
@chaholl did you publish your fork on npm ? is it useable by others ? thanks in advance
Why don't you use the proprietary AAD client libraries?
Hi @brockallen , thanks for answering. I'm not using msal.js to avoid vendor lock-in.
@chaholl did you publish your fork on npm ? is it useable by others ? thanks in advance
I didn't, sorry. I daresay the core code has moved on quite a bit since then though. FWIW, I also used this library to avoid lock-in - I needed to support multiple providers, not just AAD
Also came across this issue, and trying to implement @brockallen 's solution, but noticed that it is not possible because we only get to know the actual tenant id after we parse the JWT, and the parsing is done inside of validateJwtAttributes, so just changing the ResponseValidator wouldn't be enough.
How about adding a special case to validateJwtAttributes to only handle Active Directory logins? Active Directory is very unique, and I doubt that any other services would use the same API structure as AzureAD.
I don't think there should be any azure specific code in this library.
For what it's worth, I hacked my way around this decoding manually the token and dynamically changing the oidc-client-js "authority" configuration (you have to hack the state as well). It seems to work fine but it's still a huge hack :(
/* hack to ignore the iss check. XXX TODO to remove */
const regextoken=/id_token=[^&]*/;
const regexstate=/state=[^&]*/;
let authority;
if (window.location.hash) {
const matched_id_token=window.location.hash.match(regextoken);
const matched_state=window.location.hash.match(regexstate);
if (matched_id_token != null && matched_state != null) {
const id_token = matched_id_token[0].split('=')[1];
const state = matched_state[0].split('=')[1];
const strState = localStorage.getItem("oidc." + state);
if (strState != null) {
authority = jwtDecode(id_token).iss
// here do your own validation
//...
const storedState = JSON.parse(strState);
storedState.authority=authority;
localStorage.setItem("oidc." + state, JSON.stringify(storedState));
sessionStorage.setItem("oidc.hack.authority", authority);
}
}
}
authority = authority || sessionStorage.getItem(hackauthoritykey) || idpSettings.authority;
let settings = {
authority, // other stuff
};
new UserManager(settings);
function logout(dispatch, userManagerInstance) {
sessionStorage.removeItem(hackauthoritykey);//To remove when hack is removed
}
If anyone wanted to know how to replace the ResponseValidator with a custom one, I've managed to do it like so:
export class ResponseValidatorCtor {
constructor (settings) {
this._settings = settings
}
validateSigninResponse (state, response) {
// validation goes here
return response
}
validateSignoutResponse (state, response) {
// validation goes here
return Promise.resolve(response)
}
}
const settings = {
client_id,
redirect_uri,
...
ResponseValidatorCtor
}
const mgr = new oidc.UserManager(settings)
Still need to do some testing but seems to do the job so far.