My question is almost similar to one mentioned in 'Auth Provider with per-user Named Credential' (Auth Provider with per-user Named Credential).
I am trying to authenticate and make a API call when a new or existing Salesforce community users try to log in. The Authentication is provided by 3rd party (Cognito).
So, the requirement is :
- User to be authenticated using the 3rd party system for login.
- After successful authentication and before community page is displayed, the API call is to be made to 3rd party system to get more details about the user.
In order to achieve this:
- Created an Open ID Connect Auth. Provider
- Use the registration handler on the Auth. Provider to create/link a new/existing user.
- Use a login flow for API call.
- Use Per User Identity Type Named Credential to make API calls.
No, where I am having issue is once the user has authenticated successfully, how do I allow the user to make API call without authenticating it again. I am getting the error:
An Apex error occurred: System.UnexpectedException: You don't have permission to view this data, enter credentials for the named credential in your personal settings. Or ask your Salesforce admin for help.
I believe this error is due to the fact that the user is not listed under 'Authentication setting for External Systems'.
My requirement doesn't allow me to authenticate the user again, so how do I achieve this using either APEX or any other way?