Skip to content

Latest commit

 

History

History
32 lines (25 loc) · 1.22 KB

File metadata and controls

32 lines (25 loc) · 1.22 KB

Using DPoP with HelseID.Library

The library handles creation of DPoP proofs using the IDPoPProofCreatorForApiRequests interface:

IDPoPProofCreatorForApiRequests dPopProofCreator = ...;

var dPopProof = await dPopProofCreator.CreateDPoPProofForApiRequest(httpMethod, url, accessTokenResponse);

To perform a Http request with the DPoP proof header and the Authorization header set you can either use the supplied extension method for the HttpRequestMessage class or you can set the headers manually:

...
var apiRequest = new HttpRequestMessage(HttpMethod.Get, url);
apiRequest.SetDPoPTokenAndProof(accessTokenResponse, dPoPProof);

var response = await httpClient.SendAsync(apiRequest);
...

Or set the headers manually

// Either directly on the HttpClient:
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("DPoP", accessTokenResponse.AccessToken);
httpClient.DefaultRequestHeaders.Add("DPoP", dpopProof);

// Or on the HttpRequestMessage:
var apiRequest = new HttpRequestMessage();
apiRequest.Headers.Authorization = new AuthenticationHeaderValue("DPoP", accessTokenResponse.AccessToken);
apiRequest.Headers.Add("DPoP", dpopProof);