-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Add Support for Customizable OpenID Profile Fields via Environment Variable #4362
base: main
Are you sure you want to change the base?
Add Support for Customizable OpenID Profile Fields via Environment Variable #4362
Conversation
Thanks, I will include your changes with the next release cycle as a lot of people depend on OpenID, and I am very careful with updating things here. This should be done in the next few days. |
@@ -73,6 +73,33 @@ function convertToUsername(input, defaultValue = '') { | |||
return defaultValue; | |||
} | |||
|
|||
async function mapCustomOpenIdData(accessToken, customOpenIdFields) { | |||
const customData = {}; | |||
const fieldsQueryURL = `https://graph.microsoft.com/v1.0/me?$select=${customOpenIdFields.join(',')}`; |
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.
This seems unique to Microsoft OpenID services. The PR notes and documentation write-up make it seem like it could be applicable to many different OIDC providers but I don't think this is usually the case.
Different OIDC providers may have different ways of accessing additional user information:
- Google has its People API
- Auth0 has its Management API
- Okta has its User API
- etc.
1 or more of these approaches would be fine for me to merge:
-
Make it explicitly Microsoft-specific and name it accordingly (e.g.,
mapMicrosoftCustomOpenIdData
) -
Make it provider-agnostic by:
async function mapCustomOpenIdData(accessToken, customOpenIdFields, providerConfig) {
const { userInfoEndpoint, fieldMapping } = providerConfig;
// Use configurable endpoint and field mapping logic
// ...
}
- Create an abstraction layer with provider-specific implementations:
const PROVIDER_MAPPERS = {
microsoft: MicrosoftDataMapper,
google: GoogleDataMapper,
// Add more providers as needed
};
class OpenIdDataMapper {
static getMapper(provider) {
const MapperClass = PROVIDER_MAPPERS[provider];
if (!MapperClass) {
throw new Error(`No mapper found for provider: ${provider}`);
}
return new MapperClass();
}
}
// Example implementations
class MicrosoftDataMapper {
async mapCustomData(accessToken, customOpenIdFields) {
const fieldsQueryURL = `https://graph.microsoft.com/v1.0/me?$select=${customOpenIdFields.join(',')}`;
// Microsoft-specific implementation...
}
}
class GoogleDataMapper {
async mapCustomData(accessToken, customOpenIdFields) {
const fieldsQueryURL = `https://people.googleapis.com/v1/people/me...`;
// Google-specific implementation...
}
}
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 would prefer the 3rd approach, since that seems like it would be the cleanest and easily allow implementations for Okta, Microsoft, etc.
This feature introduces a new environment variable, OPENID_CUSTOM_DATA, that allows developers to define which fields from the OpenID profile should be dynamically fetched and stored in the user model. The fields specified in this variable will be fetched from the OpenID provider (e.g., Microsoft Graph API) and saved in a new, flexible customOpenIdData field in the user schema.
Documentation Updates Notice: here
Summary
Better explanation could be found in this Feature Request
Change Type
Please delete any irrelevant options.
Checklist
Please delete any irrelevant options.