I have a Spring Boot app that’s going to use Spring Security and Okta to lock down the API endpoints.
The setup there is fairly straight forward. I also need to be able to use javascript to post to an endpoint and I believe I need to set the Bearer token in the Authorization header.
By the time the user is on the page with the javascript post, they will already be signed in to Okta.
I’ve tried to use the javascript examples as shown here
but I’m not able to get to the token. The user has a session so the console will show “Welcome back, (user info here)”
I’m basically trying to do what callMessagesApi() is showing but the access token is not there since the user has a session and the following javascript did not run:
// Save the tokens for later use, e.g. if the page gets refreshed:
oktaSignIn.tokenManager.add('accessToken', accessToken);
What’s the correct way to get access to the token so that I can send it back to the server?
Thanks but this didn’t work for me. I changed the baseUrl, clientId, redirectUri and Issuer.
btw, what is ausmr67xnx0PrAbI7356 from your example?
It should be something like this right?
issuer: "https://my dev ##.okta.com/oauth2/default
Once I change the values and run I get the Okta screen, user logs in, the console log never happens, I added javascript alert messages, those never pop up.
The page redirects to another login that is not Okta branded.
I have a page that i can navigate to and check the user information. It’s all there so I know the user is logged in ok.
Also, when I do this I’m always using incognito mode.
I figured out a way to solve my issue by having the javascript do a form post so that the browser sends the cookies / headers to the backend.
It still would be nice to have a working example on how to post with javascript and be authenticated.