The following code works in Python: (from this)
import logging
import requests
import json
AUTH_CLIENT_ID = "<AZURE_OAUTH_CLIENT_ID>"
AUTH_CLIENT_SECRET = "<AZURE_OAUTH_CLIENT_SECRET>"
AUTH_GRANT_TYPE = "password"
SCOPE_URL = "<AZURE_SCOPE_URL>"
TOKEN_URL = "<AZURE_TOKEN_URL>"
PAYLOAD = "client_id={clientId}&" \
"client_secret={clientSecret}&" \
"username={userName}&" \
"password={password}&" \
"grant_type={grantType}&" \
"scope={scopeUrl}".format(clientId=AUTH_CLIENT_ID, clientSecret=AUTH_CLIENT_SECRET, userName=USER,
password=PASSWORD, grantType=AUTH_GRANT_TYPE, scopeUrl=SCOPE_URL)
print("Getting JWT token")
response = requests.post(TOKEN_URL, data=PAYLOAD)
json_data = json.loads(response.text)
TOKEN = json_data['access_token']
print("Token obtained")
But I searched for a few days and I cannot find anything useful to get the equivalent in C#. Could anyone please help?
Posts/Example I've tried:
How do I get an OAuth 2.0 authentication token in C#
How to write OAuth2 Web API Client in Asp.net MVC
https://www.luisquintanilla.me/posts/client-credentials-authentication-csharp.html
...and so on
Thank you.