We are trying to make a REST call to an external system using apex_web_service.make_rest_request following the OAUTH2 authentication method, which is deployed in AWS. We have got a Token URL (Login URL) and Original API URLs to fetch the actual business data with Bearer token authentication.
When we are following two step authentication in our code, i.e, fetching the token from Token URL using Basic Authentication and supplying the token to call the main API URLs by setting the Authorization header it is working fine and we get the results.
But when we are trying to pass the Token URL along with the username/passwords to make_rest_request call to main URL, the result is returning Unauthorized error.
When we try to call oauth_authenticate for token URL, it is returning unauthorized error as well.
The credential we have initially using as Basic Authentication and checked the logs at target system. It was showing that make_rest_request is making a call to the actual API URL with basic authentication, which is not valid.
Then we changed the credential type to OAUTH2.0 flow and checked the logs in target system. We see now, it is calling the Token URL with necessary parameters set with basic authentication, the response shows Access Tokens are returned. But, it's not further proceeding to call the actual API URL with Bearer Authorization.
Attached are some sample files that we tried.
Thanks
Sandipan
AWS Log token URL with Basic Auth Cred.txt

oauth_authenticate call.txt
Toekn URL Script with OAUTH2 Cred.txt
Two step token retrieve.txt