Open rudeshko-traderev opened 4 years ago
@rudeshko-traderev
It is expected that the 302 has no response body. The code will be in the URL returned in the response headers from the 302 response. In this case, it looks like it will be something like http://localhost:8000#code=XXX
A few things may be going wrong here:
1) Try adding a trailing slash after your redirectURI. Certain browsers will drop the hash fragment if the URL path does not end with a path
2) Try using responseMode: 'query' in your authJS config. This will pass the code in the URL query instead of the hash fragment
3) We typically recommend using a dedicated route/path for handling the callback. The reason is that there may be other logic running on your main route which may interfere with handling the redirect callback. Typically we do a redirect login flow by first saving the current location, then redirecting to Okta. On the redirect callback, call parseFromUrl
which reads the tokens from the URL, rewrites the URL so the tokens are no longer present, and then saves the tokens in storage. After this, it reads the "original" location from storage and redirects to the path that began the login flow.
It is OK to handle the callback from the root path, but you must be careful to understand whether you are loading the app in an authenticated state, an unauthenticated state, or in the callback handler. I would recommend testing for the existence of the param "code" in the URL (either in hash fragment or query, depending on how responseMode
is configured). If the code exists in the URL, this is the signal that your app should handle the callback and not perform ANY other logic to determine if the user is authenticated (such as tokenManager.get). After the callback has been handled and tokens are stored, it will be safe to call tokenManager.get. If it is called before/during a callback there may be a race condition.
@rudeshko-traderev - Did any of the above suggestions help with your experience?
@rudeshko-traderev - It will also be helpful to know whether your client is a SPA or WEB type. Both types can use the implicit flow, but PKCE is only for SPA applications. WEB clients will use the "authorization_code" flow. We will be happy to continue assisting you with your issue, if it still exists. Thanks!
@aakashyadav-okta I am facing the same issue with authorization_code
@anandadvisory probably you got the wrong Aakash
@anandadvisory Were you able to find a resolution for this issue?
I was using implicit flow for the initial stages of our application, and it was working fine, but once I switched from
responseType: "token"
toresponseType: "code"
, the library doesn't seem to be returning the tokens when it's exchanging the authorization code for the tokens.I can see that in the browser it has the authorization code, and my custom state parameter, and in Angular 1 I am calling
parseFromUrl
which returns{tokens: {}, state: "okta-custom-state", code: undefined}
.I am using another Okta instance as the idp, so in the initial call to
getWithRedirect
, I pass theidp
parameter. It might be related.I also don't see the call to the
/token
endpoint in the Network tab, only the first call to:And it responds with
302
and no response body.Does anyone have any ideas on why this might be happening? I noticed in the library itself, if the following fails, it doesn't make the call, but I am not sure if that's the reason.
@okta/okta-auth-js/token.js:241: