In Is it safe to expose client_id, client_secret, and audience on HTML pages?, I asked if it is safe to expose client_id
and client_secret
in a static site’s pages or scripts and scripts and @luis.rudge kindly answered that, in short, no:
client_id: yes. client_secret, absolutely not. We encode tokens with that secret, so, anyone having this secret can emit tokens that your application will think it’s safe.
Also, from a web page, you shouldn’t be calling the oauth/token endpoint. Please follow our jquery quick starts: https://auth0.com/docs/quickstart/spa/jquery/01-login
A corollary of that is that I can’t send POST
requests to an AWS API Gateway based API that is protected using a Custom Authorizer like this:
var settings = {
"async": true,
"crossDomain": true,
"url": "https://xyz.auth0.com/oauth/token",
"method": "POST",
"headers": {
"content-type": "application/json"
},
"data": "{\"client_id\":\"...\",\"client_secret\":\"...\",\"audience\":\"...\",\"grant_type\":\"client_credentials\"}"
}
$.ajax(settings).done(function (response) {
console.log(response);
});
On the other hand, my custom authorizer, expects a JWT in the request to authorize a request to my API.
How can a single page application produce this JWT to pass it to the API in AJAX request Authorization
headers?