From c40287555c55a0ab28dc09db44617da4298e8733 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Wed, 28 Jun 2023 18:15:40 +0200 Subject: [PATCH 1/2] Inclde an Accept header by default to request JSON responses. --- .../TestAuthorizedServicesController.cs | 14 +++++++++++++ .../AssetBankSearchResponse.cs | 20 +++++++++++++++++++ ...ngs-schema.Umbraco.AuthorizedServices.json | 10 +++++++++- .../appsettings.json | 16 +++++++++++++++ .../Implement/AuthorizedRequestBuilder.cs | 1 + 5 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 examples/Umbraco.AuthorizedServices.TestSite/Models/ServiceResponses/AssetBankSearchResponse.cs diff --git a/examples/Umbraco.AuthorizedServices.TestSite/Controllers/TestAuthorizedServicesController.cs b/examples/Umbraco.AuthorizedServices.TestSite/Controllers/TestAuthorizedServicesController.cs index fe3bab5..0e991cf 100644 --- a/examples/Umbraco.AuthorizedServices.TestSite/Controllers/TestAuthorizedServicesController.cs +++ b/examples/Umbraco.AuthorizedServices.TestSite/Controllers/TestAuthorizedServicesController.cs @@ -86,5 +86,19 @@ public async Task GetFoldersFromDropbox() return Content(response); } + + public async Task GetAssetsFromAssetBank(string assetIds) + { + AssetBankSearchResponse? response = await _authorizedServiceCaller.GetRequestAsync( + "assetBank", + "/assetbank-rya-assets-test/rest/asset-search?assetIds=" + assetIds); + + if (response == null) + { + return Problem("Could not retrieve assets."); + } + + return Content(string.Join(", ", response.Select(x => x.ToString()))); + } } diff --git a/examples/Umbraco.AuthorizedServices.TestSite/Models/ServiceResponses/AssetBankSearchResponse.cs b/examples/Umbraco.AuthorizedServices.TestSite/Models/ServiceResponses/AssetBankSearchResponse.cs new file mode 100644 index 0000000..a22a657 --- /dev/null +++ b/examples/Umbraco.AuthorizedServices.TestSite/Models/ServiceResponses/AssetBankSearchResponse.cs @@ -0,0 +1,20 @@ +using System.Text.Json.Serialization; + +namespace Umbraco.AuthorizedServices.TestSite.Models.ServiceResponses; + +public class AssetBankSearchResponse : List +{ +} + +public class AssetBankAsset +{ + public int Id { get; set; } + + [JsonPropertyName("originalFilename")] + public string OriginalFileName { get; set; } = string.Empty; + + public override string ToString() => $"{OriginalFileName} ({Id})"; +} + + + diff --git a/examples/Umbraco.AuthorizedServices.TestSite/appsettings-schema.Umbraco.AuthorizedServices.json b/examples/Umbraco.AuthorizedServices.TestSite/appsettings-schema.Umbraco.AuthorizedServices.json index b1dfce6..bc15edd 100644 --- a/examples/Umbraco.AuthorizedServices.TestSite/appsettings-schema.Umbraco.AuthorizedServices.json +++ b/examples/Umbraco.AuthorizedServices.TestSite/appsettings-schema.Umbraco.AuthorizedServices.json @@ -64,7 +64,7 @@ }, "AuthorizationUrlRequiresRedirectUrl": { "type": "boolean", - "description": "Gets or sets the path for requests for working with service tokens." + "description": "Gets or sets a value indicating whether authorization requests require sending the redirect URL." }, "RequestTokenPath": { "type": "string", @@ -74,6 +74,14 @@ "type": "string", "description": "Gets or sets the format to use for encoding the request for a token." }, + "JsonSerializer": { + "type": "string", + "description": "Gets or sets the JSON serializer to use when building requests and deserializing responses." + }, + "AuthorizationRequestRequiresAuthorizationHeaderWithBasicToken": { + "type": "boolean", + "description": "Gets or sets a value indicating whether the basic token should be included in the token request." + }, "ClientId": { "type": "string", "description": "Gets or sets the client Id for the app registered with the service." diff --git a/examples/Umbraco.AuthorizedServices.TestSite/appsettings.json b/examples/Umbraco.AuthorizedServices.TestSite/appsettings.json index 2292274..5efecfc 100644 --- a/examples/Umbraco.AuthorizedServices.TestSite/appsettings.json +++ b/examples/Umbraco.AuthorizedServices.TestSite/appsettings.json @@ -26,6 +26,22 @@ "AuthorizedServices": { "TokenEncryptionKey": "", "Services": [ + { + "Alias": "assetBank", + "DisplayName": "Asset Bank", + "ApiHost": "https://rya-assets-test.assetbank-server.com", + "IdentityHost": "https://rya-assets-test.assetbank-server.com", + "TokenHost": "https://rya-assets-test.assetbank-server.com", + "RequestIdentityPath": "/assetbank-rya-assets-test/oauth/authorize", + "AuthorizationUrlRequiresRedirectUrl": true, + "RequestTokenPath": "/assetbank-rya-assets-test/oauth/token", + "RequestTokenFormat": "FormUrlEncoded", + "JsonSerializer": "SystemTextJson", + "ClientId": "", + "ClientSecret": "", + "Scopes": "", + "SampleRequest": "/assetbank-rya-assets-test/rest/asset-search?assetIds=28039" + }, { "Alias": "github", "DisplayName": "GitHub", diff --git a/src/Umbraco.AuthorizedServices/Services/Implement/AuthorizedRequestBuilder.cs b/src/Umbraco.AuthorizedServices/Services/Implement/AuthorizedRequestBuilder.cs index 7cc23e2..72ba759 100644 --- a/src/Umbraco.AuthorizedServices/Services/Implement/AuthorizedRequestBuilder.cs +++ b/src/Umbraco.AuthorizedServices/Services/Implement/AuthorizedRequestBuilder.cs @@ -29,6 +29,7 @@ public HttpRequestMessage CreateRequestMessage( requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken); requestMessage.Headers.UserAgent.Add(new ProductInfoHeaderValue("UmbracoServiceIntegration", "1.0.0")); + requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); return requestMessage; } From 650a4ed03a1253373b11558aee6a227c6fe90da6 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Wed, 28 Jun 2023 18:16:03 +0200 Subject: [PATCH 2/2] Bumped version to 0.1.2. --- version.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.json b/version.json index 1318f79..b367596 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "0.1.1", + "version": "0.1.2", "assemblyVersion": { "precision": "build" },