-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
feat: Flexible fields mapping for AAD user info and FAB user #1912
base: master
Are you sure you want to change the base?
Conversation
@passren Could you please fix black formatting to get it like that:
|
@passren I tried above patch and new mapping with |
@krionbsd just remove "upn" from client_kwargs > scope, like this: "client_kwargs": { |
I don't have upn in client_kwargs scope, but instead |
That's strange. Please check if "user_info_mapping" was placed under client_kwargs. Only if the code can't get mapping from config file, it will try to get default "upn" from AAD user response. |
@passren I have tested your change with Superset and found that it works and addresses the claim mapping issue. @dpgaspar can we get this change checked in? @krionbsd It's possible your config was missing something, or you were missing the passren's change. Here's what I used: OAUTH_PROVIDERS = [
{
"name": "azure",
"icon": "fa-windows",
"token_key": "access_token",
"remote_app": {
"client_id": "{{CLIENT_ID}}",
"client_secret": os.environ.get("AZURE_SECRET"),
"api_base_url": "https://login.microsoftonline.com/{{TENANT_ID}}/oauth2/v2.0/",
"client_kwargs": {
"scope": "User.read email profile openid",
"resource": "{{CLIENT_ID}}",
"user_info_mapping":
{
"name": ("name", ""),
"email": ("email", ""),
"first_name": ("given_name", ""),
"last_name": ("family_name", ""),
"id": ("oid", ""),
"username": ("preferred_username", ""),
"role_keys": ("roles", []),
}
},
"request_token_url": None,
"access_token_url": "https://login.microsoftonline.com/{{TENANT_ID}}/oauth2/v2.0/token",
"authorize_url": "https://login.microsoftonline.com/{{TENANT_ID}}/oauth2/v2.0/authorize",
"jwks_uri": "https://login.microsoftonline.com/common/discovery/v2.0/keys"
}
}
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change looks good for me. I have try it in my projects and succeeded.
I've been using dex as OpenID provider which drives authentication to Azure, for whatever reasons I'm still getting the error with above mentioned config as well as with @passren patch:
|
@georgewfisher If you are trying to config AAD in Superset, you could refer to this: Config Superset > Custom OAuth2 Configuration. import logging
from superset.security import SupersetSecurityManager
class AADSecurityManager(SupersetSecurityManager):
def oauth_user_info(self, provider, response=None):
logging.debug("Oauth2 provider: {0}.".format(provider))
if provider == 'azure':
logging.debug("Azure response received : {0}".format(response))
id_token = response["id_token"]
logging.debug(str(id_token))
me = self._azure_jwt_token_parse(id_token)
logging.debug("Parse JWT token : {0}".format(me))
return {
"name": me.get("name", ""),
"email": me["email"],
"first_name": me.get("given_name", ""),
"last_name": me.get("family_name", ""),
"id": me["oid"],
"username": me["preferred_username"],
"role_keys": me.get("roles", []),
} Then set this manager class in config file, like this: from custom_sso_security_manager import AADSecurityManager
CUSTOM_SECURITY_MANAGER = AADSecurityManager |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this and it works.
but this is not correct procedure right because when we are deploying production how can we edit manager clients are not acceptable that way please give me better solution Thanks.. |
May I know why this PR is still being pending? Thank u all your guys work. |
Description
Currently in security module for AAD OAuth, if get user info from AAD, the module will return a fixed values which map user info from AAD to fab user as below:
But I found some of fields from AAD may be missed like "upn" can't retrieve from AAD, and the fixed mapping doesn't meet my requirements, like "email" should map to me["email"] in my scenario.
This PR is to enable the fields mapping can be set in config.py for more flexible configuration.
The new mapping structure is blow:
The field mapping shall look like this
"<FAB user info field>": ("<user info field from AAD>", <default value if no this field from AAD>)
.The fields mapping will be put into this path: OAUTH_PROVIDERS > {provider: azure} > "remote_app" > "client_kwargs"
ADDITIONAL INFORMATION