okta / okta-auth-js

The official js wrapper around Okta's auth API
Other
451 stars 265 forks source link

Custom sign in using signInWithCredentials + setCookieAndRedirect not works. #1311

Open sb-developers opened 2 years ago

sb-developers commented 2 years ago

Describe the bug?

Hi, We're trying to develop a custom register process and finally, when user finish registering, we want to sign in into application. For this, we are using this documentation: https://github.com/okta/okta-auth-js/blob/master/docs/authn.md#signinwithcredentialsoptions. But when execute those functions, not works.... We want to redirect to a private page, but always send us to Login. We see that in Browser's LocalStorage, okta-token-storage is empty, and we thought that it will be completed. What wrong with this?

What is expected to happen?

We expect to finally sign in user and redirect to our private page.

What is the actual behavior?

In our case goes to Login page.

Reproduction Steps?

1) Custom Register User. 2) Call signInWithCredentials with user and password. 3) Call setCookieAndRedirect with the sessionToken get in signInWithCredentials response and a private page. 4) Instead of go to provate page, goes to Login. USer not sign in.

SDK Versions

"@okta/okta-angular": "^5.1.1" "@okta/okta-auth-js": "^6.1.0" "@okta/okta-signin-widget": "^6.0.1"

Execution Environment

Angular Firefox

Additional Information?

No response

jaredperreault-okta commented 2 years ago

Can you provide a code snippet illustrating the usage of these methods?

ikermonk commented 1 year ago

Hi Jared, Sorry for taking so long to reply, but i can't create and example to illustrate you.

For example we are trying to do a custom login, and we use those functions:

` async login(username: string, password: string) {

console.log("Login: ", username + " // " + password);
const transaction = await this.authClient.signIn({username, password});

if (transaction.status !== 'SUCCESS') {
  throw Error('We cannot handle the ' + transaction.status + ' status');
}
this.isAuthenticated.next(true);

this.authClient.session.setCookieAndRedirect(transaction.sessionToken, environment.appDomain + "/new-audit-configuration");

}`

This code try to logged in Okta but not create the Cookie in LocalStorage and not works for me, but the request returns success and in network appears this request: https://dev-30360365.okta.com/api/v1/sessions/me with the correct data. I think that we only need LocalStorage Cookies to can works fine.

The transaction gives us this information: Transaction:
Object { data: {…}, status: "SUCCESS", expiresAt: "2022-11-29T18:31:24.000Z", sessionToken: "20111_FESyj3uunPWwuWj_Tu6MwPphuTtV_s7NZdyHBvb2w51sUjpFL",

Can you help us?

Thanks!