I downloaded angular + Okta example from here https://github.com/okta/samples-js-angular/tree/master/okta-hosted-login and NodeJs example from here https://github.com/okta/samples-nodejs-express-4/tree/master/resource-server
And ran both client and server, I am able to login using my okta developer account. I can able to navigate to message route, getting right information.
But I need access token immediately after login success. So I modified app.component.ts(https://github.com/okta/samples-js-angular/blob/master/okta-hosted-login/src/app/app.component.ts), added below code in ngOnInit() to check if access token available or not. I got null. If I refresh page, then I see access token in browser console.
const accessToken = await this.oktaAuth.getAccessToken(); console.log(" access token ", accessToken);
Am I doing anything wrong here, Okta access token not available for immediate use ? I have requirement in my application that once user successfully logged in, need to make a API call with token, to verify if token is valid or not and to get user information to show in UI on home page.
Please let me know if you need more information.