Hello Okta Folks,
I have two users in Okta.
- aakash.banerjee@gmail.com (Super Admin)
- aakashbanerjee@outlook.com (User created using Create New User api and activated)
What I am trying to achieve is pretty simple. Once a user logs in to the web app the current logged in users’s email is displayed in navbar, screenshot below.
I am using Angular 5 as the frontend framework btw so below are some code fragments and my thought process.
My navbar component in its ngOnInit() will call a method getuserLoggedin() if oktaAuth.isAuthenticated() is true. This is nothing but a method in my service that pings Okta’s get current user api: https://dev-179941.oktapreview.com/api/v1/users/me
ngOnInit() {
if(this.oktaAuth.isAuthenticated()){
this.getcurrentUser.getuserLoggedin().subscribe(data =>{
console.log(data);
},
(err : HttpErrorResponse) => {
//error handling etc
});
Service Code fragment looks something like this.
@Injectable()
export class FileService {
apikey = 'SSWS myapikey';
getuseroktaurl = 'https://dev-179941.oktapreview.com/api/v1/users/me';
constructor(private http: HttpClient, private oktaAuth: OktaAuthService) { }
getuserLoggedin(token) : Observable<any>{
return this.http.get(this.getuseroktaurl, {
headers: new HttpHeaders().set('Accept', 'application/json').set('Content-Type', 'application/json').set('Authorization', this.apikey),
});
}
Now that I have set the stage up for disappointment. Here is whats happening. If I login in with my super admin user aakash.banerjee@gmail.com or a normal user aakashbanerjee@outlook.com the get current user api returns the admin user login so no matter who logs in the navbar shows the admin user email. I am wondering why is that?
On closer look at the browser console below is the error I see first time when the user authenticates and /implicit/callback hits.
ERROR Error: Uncaught (in promise): AuthSdkError: Unable to parse a token from the url
Error
at Object.../../../../@okta/okta-auth-js/lib/errors/AuthSdkError.js (AuthSdkError.js:26)
at __webpack_require__ (bootstrap d941f41afcbce05d7983:54)
at Object.../../../../@okta/okta-auth-js/lib/storageBuilder.js (storageBuilder.js:1)
at __webpack_require__ (bootstrap d941f41afcbce05d7983:54)
at Object.../../../../@okta/okta-auth-js/lib/storageUtil.js (storageUtil.js:2)
at __webpack_require__ (bootstrap d941f41afcbce05d7983:54)
at Object.../../../../@okta/okta-auth-js/lib/http.js (http.js:4)
at __webpack_require__ (bootstrap d941f41afcbce05d7983:54)
at Object.../../../../@okta/okta-auth-js/lib/tx.js (tx.js:2)
at __webpack_require__ (bootstrap d941f41afcbce05d7983:54)
at Object.../../../../@okta/okta-auth-js/lib/errors/AuthSdkError.js (AuthSdkError.js:26)
at __webpack_require__ (bootstrap d941f41afcbce05d7983:54)
at Object.../../../../@okta/okta-auth-js/lib/storageBuilder.js (storageBuilder.js:1)
at __webpack_require__ (bootstrap d941f41afcbce05d7983:54)
at Object.../../../../@okta/okta-auth-js/lib/storageUtil.js (storageUtil.js:2)
at __webpack_require__ (bootstrap d941f41afcbce05d7983:54)
at Object.../../../../@okta/okta-auth-js/lib/http.js (http.js:4)
at __webpack_require__ (bootstrap d941f41afcbce05d7983:54)
at Object.../../../../@okta/okta-auth-js/lib/tx.js (tx.js:2)
at __webpack_require__ (bootstrap d941f41afcbce05d7983:54)
at resolvePromise (zone.js:824)
at zone.js:746
at rejected (okta.service.js:24)
at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:392)
at Object.onInvoke (core.js:4753)
at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:391)
at Zone.webpackJsonp.../../../../zone.js/dist/zone.js.Zone.run (zone.js:142)
at zone.js:873
at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:425)
at Object.onInvokeTask (core.js:4744)
I investigated my api token that I am passing to the api authorization header. This was created by my super admin user. Do I have to pass something else as apitoken for every user? Instead of passing my super admin apitoken I tried passing the accessToken for the current user to the api and obviously it returns a 403.
So if you guys have come across this issue and have resolved it some way your help is much appreciated.
Thank you.
Aakash.