Skip to content

Commit 4f39cbb

Browse files
authored
Merge pull request #11 from umbraco/bugfix/use-accept-header
Include an Accept header by default to request JSON responses.
2 parents 5e69fac + 650a4ed commit 4f39cbb

File tree

6 files changed

+61
-2
lines changed

6 files changed

+61
-2
lines changed

examples/Umbraco.AuthorizedServices.TestSite/Controllers/TestAuthorizedServicesController.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,19 @@ public async Task<IActionResult> GetFoldersFromDropbox()
8686

8787
return Content(response);
8888
}
89+
90+
public async Task<IActionResult> GetAssetsFromAssetBank(string assetIds)
91+
{
92+
AssetBankSearchResponse? response = await _authorizedServiceCaller.GetRequestAsync<AssetBankSearchResponse>(
93+
"assetBank",
94+
"/assetbank-rya-assets-test/rest/asset-search?assetIds=" + assetIds);
95+
96+
if (response == null)
97+
{
98+
return Problem("Could not retrieve assets.");
99+
}
100+
101+
return Content(string.Join(", ", response.Select(x => x.ToString())));
102+
}
89103
}
90104

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace Umbraco.AuthorizedServices.TestSite.Models.ServiceResponses;
4+
5+
public class AssetBankSearchResponse : List<AssetBankAsset>
6+
{
7+
}
8+
9+
public class AssetBankAsset
10+
{
11+
public int Id { get; set; }
12+
13+
[JsonPropertyName("originalFilename")]
14+
public string OriginalFileName { get; set; } = string.Empty;
15+
16+
public override string ToString() => $"{OriginalFileName} ({Id})";
17+
}
18+
19+
20+

examples/Umbraco.AuthorizedServices.TestSite/appsettings-schema.Umbraco.AuthorizedServices.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
},
6565
"AuthorizationUrlRequiresRedirectUrl": {
6666
"type": "boolean",
67-
"description": "Gets or sets the path for requests for working with service tokens."
67+
"description": "Gets or sets a value indicating whether authorization requests require sending the redirect URL."
6868
},
6969
"RequestTokenPath": {
7070
"type": "string",
@@ -74,6 +74,14 @@
7474
"type": "string",
7575
"description": "Gets or sets the format to use for encoding the request for a token."
7676
},
77+
"JsonSerializer": {
78+
"type": "string",
79+
"description": "Gets or sets the JSON serializer to use when building requests and deserializing responses."
80+
},
81+
"AuthorizationRequestRequiresAuthorizationHeaderWithBasicToken": {
82+
"type": "boolean",
83+
"description": "Gets or sets a value indicating whether the basic token should be included in the token request."
84+
},
7785
"ClientId": {
7886
"type": "string",
7987
"description": "Gets or sets the client Id for the app registered with the service."

examples/Umbraco.AuthorizedServices.TestSite/appsettings.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,22 @@
2626
"AuthorizedServices": {
2727
"TokenEncryptionKey": "",
2828
"Services": [
29+
{
30+
"Alias": "assetBank",
31+
"DisplayName": "Asset Bank",
32+
"ApiHost": "https://rya-assets-test.assetbank-server.com",
33+
"IdentityHost": "https://rya-assets-test.assetbank-server.com",
34+
"TokenHost": "https://rya-assets-test.assetbank-server.com",
35+
"RequestIdentityPath": "/assetbank-rya-assets-test/oauth/authorize",
36+
"AuthorizationUrlRequiresRedirectUrl": true,
37+
"RequestTokenPath": "/assetbank-rya-assets-test/oauth/token",
38+
"RequestTokenFormat": "FormUrlEncoded",
39+
"JsonSerializer": "SystemTextJson",
40+
"ClientId": "",
41+
"ClientSecret": "",
42+
"Scopes": "",
43+
"SampleRequest": "/assetbank-rya-assets-test/rest/asset-search?assetIds=28039"
44+
},
2945
{
3046
"Alias": "github",
3147
"DisplayName": "GitHub",

src/Umbraco.AuthorizedServices/Services/Implement/AuthorizedRequestBuilder.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public HttpRequestMessage CreateRequestMessage<TRequest>(
2929

3030
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken);
3131
requestMessage.Headers.UserAgent.Add(new ProductInfoHeaderValue("UmbracoServiceIntegration", "1.0.0"));
32+
requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
3233
return requestMessage;
3334
}
3435

version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"assemblyVersion": {
55
"precision": "build"
66
},

0 commit comments

Comments
 (0)