I am using OKTA for user management and I am having an issue getting user information back. I have followed the documentation, I have CORS set correctly, enabled app permissions, etc.
If I test using postman I get the data back without a problem. It's only when react makes the api call that a 401 is returned. I have also narrowed down the headers causing the problem origin
and referrer
.
I am using okta/react I have searched for days and can't figure out what I'm missing. Does anyone have any suggestions or ideas?
ReactJS Code
useEffect(() => {
if (!authState.isAuthenticated) {
// When user isn't authenticated, forget any user info
setUserInfo(null);
} else {
oktaAuth
.getUser()
.then((info) => {
setUserInfo(info);
})
.catch((error) => {
// ToDo: log error
console.error(error);
});
}
}, [authState, oktaAuth]);
Request Headers: unAuthorized
GET /oauth2/default/v1/userinfo HTTP/2
Host: myHost.okta.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:88.0) Gecko/20100101 Firefox/88.0
Accept: application/json
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Referer: http://localhost:1234/
Content-Type: application/json
X-Okta-User-Agent-Extended: @okta/okta-react/5.1.1 okta-auth-js/4.8.0
Authorization: Bearer sometoken
Origin: http://localhost:1234
Connection: keep-alive
Cookie: myCookie
Pragma: no-cache
Cache-Control: no-cache
TE: Trailers
Request Headers: Success
GET /oauth2/default/v1/userinfo HTTP/2
Host: myHost.okta.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:88.0) Gecko/20100101 Firefox/88.0
Accept: application/json
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Content-Type: application/json
X-Okta-User-Agent-Extended: @okta/okta-react/5.1.1 okta-auth-js/4.8.0
Authorization: Bearer sometoken
Connection: keep-alive
Cookie: myCookie
Pragma: no-cache
Cache-Control: no-cache
TE: Trailers