Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get a StateToken for basic Authentication through Okta with .net sdk?

I am building an internal Web API(asp.net) and I need to integrate our Okta authentication with it. I have the SDK installed through NuGet and I am able to do simple things like get a User and see there Profile.

What I really need to do though is understand how I take a User, Authenticate them through Okta, and then later validate that same User.

Here is what I have, at a basic conceptual level.

var oktaClient = new OktaClient(apiToken: "00vEX-jX3to71axEZ1L3luDfaAPH9d-ZPBV4coG2Ya", baseUri: new Uri(uriString: "https://ourcompany.oktapreview.com"));    

AuthClient authClient = oktaClient.GetAuthClient();    

AuthResponse response = authClient.Authenticate(username: "[email protected]", password: "MyPassword");

AuthResponse huh = authClient.GetStatus(response.StateToken);

The problem is that my response does not contain a StateToken. It only contains a SessionToken. So, what I could really use some help with is what I'm missing.

I've looked through the Okta Music Store(https://github.com/okta/okta-music-store) demo but that doesn't seem to answer my question. Perhaps because it's an older MVC 4 app and I'm using WebApi or just because it's a more complicated example than what I am trying to accomplish I don't know.
I have also been reading through http://developer.okta.com/docs/api/getting_started/design_principles.html and I'm still not seeing what I'm missing.

like image 675
Refracted Paladin Avatar asked Jan 19 '26 07:01

Refracted Paladin


1 Answers

I've been struggling with figuring stateToken out too, and after sifting through numerous useless responses to the same inquiry I finally found an answer:

state —; Protects against cross-site request forgery (CSRF). Can be any value.

Source: https://developer.okta.com/docs/guides/add-an-external-idp/apple/create-authz-url/

I found that I can indeed provide any arbitrary string, so long that it remains consistent throughout that user's authorization flow.

What I'm still not clear on, however, is how often the state token should be regenerated and what the best practice is for maintaining that value between page loads. My assumption is that it should be randomly generated and stored in session.

UPDATE: I found this page discussing how to generate state tokens, seems relevant.

https://pipedrive.readme.io/docs/marketplace-oauth-authorization-state-parameter

The method they recommend (at least for php ) is:

// Assign to state the hashing of the session ID
$state = hash('sha256', session_id());
like image 147
CragMonkey Avatar answered Jan 20 '26 23:01

CragMonkey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!