I have separate UI web app from the API web app. Both registered as applications in B2C. I've enabled Azure App Service Authentication / Authorization (easy auth) on the UI web app, and configured the API web app to use JwtBearer middleware to authenticate calls to API.
This seems to work, but I have trouble getting scopes through to the API web app. I have published the scopes in the API app, and configured the UI app to have access to these scopes.
I've tried different login URL options, e.g., https://myUIapp.azurewebsites.net/.auth/login/aad?p=b2c_1a_mysigninpolicy&scope=openid+https://myb2ctenant.onmicrosoft.com/api/company.read&post_login_redirect_uri=/app
and ensured that the API apps "App ID URI" (in B2C app settings) is indeed "api", while the scope name is company.read
. Still after successful authentication, when going to /.auth/me
, I do not see the scope, I do see other claims just fine.
Where should I start looking into pointers on this?
UPDATE
I've determined how I end up in this situation, but it is still unclear why:
User authenticates starting with URL such as:
https://login.microsoftonline.com/mydevb2c.onmicrosoft.com/oauth2/v2.0/authorize?p=B2C_1A_signin&client_id=UIAPP_GUID&nonce=defaultNonce&redirect_uri=https%3A%2F%2FUIAPP.azurewebsites.net%2F.auth%2Flogin%2Faad%2Fcallback&scope=openid%20https%3A%2F%2Fmydevb2c.onmicrosoft.com%2Fapi%2Fcompany.write%20https%3A%2F%2Fmydevb2c.onmicrosoft.com%2Fapi%2Fcompany.read&response_type=id_token%20token&prompt=login
After successful authentication, user is redirected to
https://UIAPP.azurewebsites.net/.auth/login/aad/callback
, as defined, BUT is immediately redirected back to authentication system with default scope set "openid+profile+email", i.e. URL such ashttps://login.microsoftonline.com/mydevb2c.onmicrosoft.com/oauth2/v2.0/authorize?response_type=id_token&redirect_uri=https%3A%2F%2FUIAPP.azurewebsites.net%2F.auth%2Flogin%2Faad%2Fcallback&client_id=UIAPP_GUID&scope=openid+profile+email&response_mode=form_post&p=b2c_1a_signinsuomifi&nonce=somenonce&state=redir%3D%252Fapp
If I take the access_token from the first callback to /.auth/login/aad/callback
it contains the requested scopes, but second authentication callback obviously doesn't as it requests default scope set.
Do I perhaps need to start the easy auth login process via .auth/login/aad
in order for it to accept the callback as well?
UPDATE 2
Yes, need to start the process via .auth/login/aad
: when using login URL such as https://myUIapp.azurewebsites.net/.auth/login/aad?p=B2C_1A_signin&redirect_uri=https%3A%2F%2FmyUIapp.azurewebsites.net%2F.auth%2Flogin%2Faad%2Fcallback&scope=openid%20https%3A%2F%2Fmydevb2c.onmicrosoft.com%2Fapi%2Fcompany.write%20https%3A%2F%2Fmydevb2c.onmicrosoft.com%2Fapi%2Fcompany.read&response_type=id_token%20token&prompt=login&post_login_redirect_uri=/app
removes the second authentication redirect.
The question now is, why do I only see the id_token in .auth/me
and not the access_token that is clearly returned to the .auth/login/aad/callback
? And ultimately: how come using the access_token as Bearer token, I still cannot query the easy auth secured API, but get error You do not have permission to view this directory or page.
? I have followed steps in Azure client app accessing Azure api secured by AD.
If I switch off easy auth, and use the JwtBearer middleware in my API, it works fine.