okta / okta-sdk-dotnet

A .NET SDK for interacting with the Okta management API, enabling server-side code to manage Okta users, groups, applications, and more.
Other
160 stars 100 forks source link

OKTA-295020 support for different content types #392

Closed bryanapellanes-okta closed 4 years ago

bryanapellanes-okta commented 4 years ago

Issue \

OKTA-295020 OKTA-302822

Code

Current behavior

The OktaClient is hard coded to only send Content-Type headers with the value of "application/json".

Desired behavior

Enable a developer to override the default Content-Type header with an alternative value when necessary.

Additional Context

Some endpoints require Content-Type header values other than "application/json", see https://developer.okta.com/docs/reference/api/apps/#request-example-45

This PR also includes POST support for collections.

bryanapellanes-okta commented 4 years ago

The execution path relevant to this change is as follows:

instantiate OktaClient -> register PayloadHandler -> client.PostAsync -> dataStore.PostAsync -> requestExecutor.PostAsync -> httpRequestMessageProvider.CreateHttpRequestMessage -> payloadHandler.SetHttpRequestMessageContent -> client.SendAsync

Below are links to the relevant tests.

[x] assert that instantiating OktaClient registers PkixCertPayloadHandler (https://github.com/okta/okta-sdk-dotnet/blob/OKTA-295020-content-types/src/Okta.Sdk.UnitTests/OktaClientShould.cs#L347) [x] assert that setting ContentType sets the PayloadHandler (https://github.com/okta/okta-sdk-dotnet/blob/OKTA-295020-content-types/src/Okta.Sdk.UnitTests/HttpRequestShould.cs#L19) [ ] assert that Publish* methods call PostAsync(HttpRequest request, Arg.Any()); no easy way to do this because ApplicationsClient is sealed (see code: https://github.com/okta/okta-sdk-dotnet/blob/OKTA-295020-content-types/src/Okta.Sdk/ApplicationsClient.cs#L62) [x] assert that PostAsync calls _dataStore.PostAsync(HttpRequest request, Arg.Any(), Arg.Any()) (https://github.com/okta/okta-sdk-dotnet/blob/OKTA-295020-content-types/src/Okta.Sdk.UnitTests/ApplicationsClientShould.cs#L194) [x] assert that DefaultDataStore.PostAsync calls _requestExecutor.PostAsync(HttpRequest request, Arg.Any()) (https://github.com/okta/okta-sdk-dotnet/blob/OKTA-295020-content-types/src/Okta.Sdk.UnitTests/DefaultDataStoreShould.cs#L402) [x] assert that DefaultRequestExecutor.PostAsync calls _httpRequestMessageProvider.CreateHttpRequestMessage(HttpRequest request, Arg.Any(), Arg.Any() (https://github.com/okta/okta-sdk-dotnet/blob/OKTA-295020-content-types/src/Okta.Sdk.UnitTests/DefaultRequestExecutorShould.cs#L115) [x] assert that HttpRequestMessageProvider.CreateHttpRequestMessage(HttpRequest request, Arg.Any()) calls HttpRequest.SetHttpRequestMessageContent (https://github.com/okta/okta-sdk-dotnet/blob/OKTA-295020-content-types/src/Okta.Sdk.UnitTests/HttpRequestMessageProviderShould.cs#L16) [x] assert that HttpRequest.SetHttpRequestMessageContent calls PayloadHandler.SetHttpRequestMessageContent (https://github.com/okta/okta-sdk-dotnet/blob/OKTA-295020-content-types/src/Okta.Sdk.UnitTests/HttpRequestShould.cs#L42) [x] assert that PayloadHandler.SetHttpRequestMessageContent sets the Content (https://github.com/okta/okta-sdk-dotnet/blob/OKTA-295020-content-types/src/Okta.Sdk.UnitTests/PayloadHandlerShould.cs#L18) [x] assert that PayloadHandler.SetHttpRequestMessageContent sets Content-Transfer-Encoding header (https://github.com/okta/okta-sdk-dotnet/blob/OKTA-295020-content-types/src/Okta.Sdk.UnitTests/PayloadHandlerShould.cs#L34)

@laura-rodriguez See above, let me know if you want to go over this together.

bryanapellanes-okta commented 4 years ago

Merging as is; known issue will be addressed in follow up.