okta / samples-aspnet

samples-aspnet
https://github.com/okta/samples-aspnet
Apache License 2.0
42 stars 107 forks source link

OKTA C# get token by user name and password #56

Open rathoregee opened 2 years ago

rathoregee commented 2 years ago

Hi Guys I am writing a integration test for aws lamda autoriser for api gateway.

do we have any c# code example to get jwt tokens (id, access) by using (username, passord)

by making c# httpclient call to Okta?

some kind of CURL for example

curl --location --request POST ‘https://org.okta.com/oauth2/v1/token’ –header ‘Accept: application/json’ –header ‘Content-Type: application/x-www-form-urlencoded’ –header ‘Content-Type: application/x-www-form-urlencoded’ –data-urlencode ‘grant_type=password’ –data-urlencode ‘username=test.user’ –data-urlencode ‘password=p@ssw0rd’ –data-urlencode ‘scope=openid’ –data-urlencode ‘client_id={{clientId}}’

andriizhegurov-okta commented 2 years ago

Hi @rathoregee, thanks for the question. I'll inquire internally if this code sample exists and let you know here.

andriizhegurov-okta commented 2 years ago

Hi @rathoregee, the flow you want to implement is not recommended. A similar flow would be the clients credentials flow, but instead of username and password you have a clientId and ClientSecret. Here you may find all the flows listed: https://developer.okta.com/docs/guides/implement-grant-type/authcode/main/#grant-type-flow

rathoregee commented 2 years ago

@andriizhegurov-okta i understand (implement is not recommended). I was writing a integration test, it is helpful there.

do we have any c# code sample for it.

many thanks

andriizhegurov-okta commented 2 years ago

@rathoregee we don't have any code samples for not recommended flows unfortunately.

rathoregee commented 2 years ago

ok- any code for PKCE (Proof Key for Code Exchange) in C# language

andriizhegurov-okta commented 2 years ago

@rathoregee no we don't have samples of PKCE flow in C#. But there are several JS resources about Authorization Code with PKCE flow that might be helpful: