<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-M74D8PB" height="0" width="0" style="display:none;visibility:hidden">
Loading
Skip to NavigationSkip to Main Content
0D51Y00006RX7iMSATOkta Classic EngineIntegrationsAnswered2019-07-17T05:03:00.000Z2019-07-15T21:08:31.000Z2019-07-17T05:03:00.000Z

KevinB.90047 (Customer) asked a question.

Port Forgot Password from SDK 0.3.3 to 1.x

I am trying to port my C* .NET code from SDK version 0.3.3 to SDK version 1.2.1.

 

Although I can validate login credentials for an existing user and I can send Forgot Password email for a user-initiated password reset, I am having trouble resetting the password. It fails with the error message:

"This operation is not allowed in the current authentication state. (403, E0000079)"

even after my code sets the user to state PasswordExpired.

 

Notes:

(1) The password policy is the same as the policy that worked for SDK version 0.3.3.

(2) This is not using an Okta app; the user never sees the Okta user interface.

(3) This does _not_ use ActiveDirectory either.

(4) This also does _not_ use MFA or even a password reset question/answer.

(5) It relies only on the token in the forgot password email to ensure that nobody can reset someone else's password. (You certainly could argue that this should be made more secure, but first I must get this simple use case working with SDK version 1.2.1.)

 

Here is an outline of what worked for SDK version 0.3.3:

 

var usersClient = new UsersClient(this.oktaApiToken, new Uri(this.oktaBaseUri));

AuthClient authClient = new AuthClient(new OktaSettings

{

   BaseUri = new Uri(this.oktaBaseUri),

   ApiToken = this.oktaApiToken

});

// This throws an exception if the password reset token is not valid.

// The value "sptoken" is from the password reset email.

Okta.Core.Models.AuthResponse authResponse = authClient.ValidateToken(sptoken);

// This throws an exception if the new password does not satisfy the complexity requirements.

usersClient.SetPassword(authResponse.Embedded.User.Id, newPassword);

 

Here is an outline of what I am attempting to do for SDK 1.2.1:

 

// Move the user account to state PasswordExpired to satisfy the SDK 1.x state transition scheme.

// (Code to get "user" object.)

Boolean? tempPassword = false;

ITempPassword x = await user.ExpirePasswordAsync(tempPassword);

 

var authClient = new AuthenticationClient(

   new Okta.Sdk.Abstractions.Configuration.OktaClientConfiguration

   {

       OktaDomain = this.oktaBaseUri,

       Token = this.oktaApiToken

   });

 

var resetPasswordOptions = new ResetPasswordOptions()

{

   NewPassword = newPassword,

   // stateToken from validating token from forgot password email.

   StateToken = stateToken,

};

// This still throws an exception even for state PasswordExpired.

//  "This operation is not allowed in the current authentication state. (403, E0000079)"

IAuthenticationResponse authResponse = await authClient.ResetPasswordAsync(resetPasswordOptions);

 

Note that the error message does _not_ say that the StateToken is invalid. Instead, it is saying that the authentication state is wrong, even though the user is in state PasswordExpired. Suggestions? Thanks.

 


  • KevinB.90047 (Customer)

    Update: I opened a Support Case to add the option to _not_ require a password recovery question / answer. Soon afterward I received email that the option had been added to my Okta organization. (That was fast!) Then UNchecking the new "Security question" checkbox in the admin user interface (as described above) completely solved my problem.

     

    Now when a user receives and responds to Forgot Password email, the authentication status goes directly to PASSWORD_RESET and the C# code can set the new password directly, as it did for SDK version 0.3.3. Previously, the authentication status went to state RECOVERY, which required answering a password recovery question.

    Expand Post
    Selected as Best
  • KevinB.90047 (Customer)

    I have a partial resolution and an updated question.

     

    First, the idea to expire the password came from discussions online about a different path through the state transition diagram at:

      https://developer.okta.com/docs/reference/api/authn/#transaction-state

    But I was starting at "Forgot Password", which does not lead through the authentication state "PASSWORD_EXPIRED", so expiring the password did not help.

     

    I finally was able to do a successful password reset with SDK 1.2.1, but only after creating a security question/answer for the user and then supplying that answer in a call of the form:

     

    IAuthenticationResponse authResponse = await authClient.AnswerRecoveryQuestionAsync(

       new AnswerRecoveryQuestionOptions { StateToken = stateToken, Answer = answer });

     

    For SDK 1.2.1 is it necessary to supply a security question answer? For SDK 0.3.3 that was not necessary. One could just reset the password directly from the C# code without reference to any security question/answer or any authentication or recovery state.

     

    Update: According to the Dec. 3, 2018 reply at:

    https://support.okta.com/help/s/question/0D50Z00008dlA11SAE/remove-recovery-question-and-answer-forgot-password-api

     

    "In order for the users to not be prompted to set up a Security Question + Answer, you have to uncheck this option in your Okta Admin Console -> Security -> Authentication -> Password, under "Additional self-service recovery option" . . . Also, in case you don't have the option to uncheck the Recovery Question, it probably needs to be enabled, so please open a Support case with us."

     

    Would unchecking that option enable my C# code to reset the password directly when using SDK 1.2.1, without first supplying a recovery question answer? Unfortunately, I cannot test that because no such option exists in my Okta organizations, so I will try opening a Support case.

    Expand Post
  • KevinB.90047 (Customer)

    Update: I opened a Support Case to add the option to _not_ require a password recovery question / answer. Soon afterward I received email that the option had been added to my Okta organization. (That was fast!) Then UNchecking the new "Security question" checkbox in the admin user interface (as described above) completely solved my problem.

     

    Now when a user receives and responds to Forgot Password email, the authentication status goes directly to PASSWORD_RESET and the C# code can set the new password directly, as it did for SDK version 0.3.3. Previously, the authentication status went to state RECOVERY, which required answering a password recovery question.

    Expand Post
    Selected as Best
This question is closed.
Loading
Port Forgot Password from SDK 0.3.3 to 1.x