To perform OIDC Authorization flow in C#, we can use the IdentityModel
package which provides several handy utilities.
Here is an example code snippet:
main.cs862 chars35 lines
This code snippet follows the Client Credentials
flow, but other flows like Authorization Code
or Implicit
can also be implemented similarly.
The discoveryResponse.TokenEndpoint
is the token endpoint URL returned by the OIDC discovery document.
The TokenClient
class sends a token request to the token endpoint and receives an access token.
The httpClient.SetBearerToken
method sets the token in the Authorization
header of subsequent HTTP requests.
Finally, the httpClient.GetAsync
method sends an HTTP GET request to the API endpoint, and the response is inspected for success.
Make sure to replace the {}
placeholders with actual values specific to your use case.
gistlibby LogSnag