Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyButland committed Dec 19, 2024
2 parents c03ace4 + e038755 commit 757b2b9
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning" Version="3.5.119" PrivateAssets="all" IsImplicitlyDefined="true" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435" PrivateAssets="all" IsImplicitlyDefined="true" />
<PackageReference Include="Umbraco.Code" Version="2.0.0" PrivateAssets="all" IsImplicitlyDefined="true" />
<PackageReference Include="Umbraco.Code" Version="2.2.0" PrivateAssets="all" IsImplicitlyDefined="true" />
<PackageReference Include="Umbraco.GitVersioning.Extensions" Version="0.2.0" PrivateAssets="all" IsImplicitlyDefined="true" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Umbraco.Cms" Version="15.0.0" />
<PackageReference Include="Umbraco.Cms" Version="15.1.1" />
<PackageReference Include="Microsoft.CodeAnalysis" Version="4.10.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,18 @@ public async Task<AuthorizationResult> AuthorizeOAuth1ServiceAsync(string servic
public async Task<AuthorizationResult> GenerateOAuth1RequestTokenAsync(string serviceAlias, string url)
{
HttpResponseMessage response = await AuthorizationRequestSender.SendOAuth1RequestForRequestToken(url);
var responseContent = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
var responseContent = await response.Content.ReadAsStringAsync();
return AuthorizationResult.AsSuccess(responseContent);
}
else
{
throw new AuthorizedServiceHttpException(
$"Error response retrieving request token for '{serviceAlias}'.",
$"Error response retrieving request token for '{serviceAlias}'. Status: {response.StatusCode}. Reason: {response.ReasonPhrase}. Content: {responseContent}.",
response.StatusCode,
response.ReasonPhrase,
await response.Content.ReadAsStringAsync());
responseContent);
}
}

Expand All @@ -97,16 +97,17 @@ private async Task<AuthorizationResult> SendRequest(ServiceDetail serviceDetail,
? await AuthorizationRequestSender.SendOAuth2ExchangeRequest(serviceDetail, parameters)
: await AuthorizationRequestSender.SendOAuth2Request(serviceDetail, parameters));

var responseContent = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
if (serviceDetail.AuthenticationMethod == AuthenticationMethod.OAuth1)
{
OAuth1Token token = await CreateOAuth1TokenFromResponse(response);
OAuth1Token token = CreateOAuth1TokenFromResponse(responseContent);
await StoreOAuth1Token(serviceDetail.Alias, token);
}
else
{
OAuth2Token token = await CreateOAuth2TokenFromResponse(serviceDetail, response);
OAuth2Token token = CreateOAuth2TokenFromResponse(serviceDetail, responseContent);
await StoreOAuth2Token(serviceDetail.Alias, token);
}

Expand All @@ -115,10 +116,10 @@ private async Task<AuthorizationResult> SendRequest(ServiceDetail serviceDetail,
else
{
throw new AuthorizedServiceHttpException(
$"Error response from token request to '{serviceDetail.Alias}'.",
$"Error response from token request to '{serviceDetail.Alias}'. Status: {response.StatusCode}. Reason: {response.ReasonPhrase}. Content: {responseContent}.",
response.StatusCode,
response.ReasonPhrase,
await response.Content.ReadAsStringAsync());
responseContent);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,11 @@ public AuthorizedServiceBase(

protected ServiceDetail GetServiceDetail(string serviceAlias) => _serviceDetailOptions.Get(serviceAlias);

protected async Task<OAuth2Token> CreateOAuth2TokenFromResponse(ServiceDetail serviceDetail, HttpResponseMessage response)
{
var responseContent = await response.Content.ReadAsStringAsync();
return _tokenFactory.CreateFromOAuth2ResponseContent(responseContent, serviceDetail);
}
protected OAuth1Token CreateOAuth1TokenFromResponse(string responseContent) =>
_tokenFactory.CreateFromOAuth1ResponseContent(responseContent);

protected async Task<OAuth1Token> CreateOAuth1TokenFromResponse(HttpResponseMessage response)
{
var responseContent = await response.Content.ReadAsStringAsync();
return _tokenFactory.CreateFromOAuth1ResponseContent(responseContent);
}
protected OAuth2Token CreateOAuth2TokenFromResponse(ServiceDetail serviceDetail, string responseContent) =>
_tokenFactory.CreateFromOAuth2ResponseContent(responseContent, serviceDetail);

protected async Task<OAuth2Token?> GetStoredToken(string serviceAlias) => await OAuth2TokenStorage.GetTokenAsync(serviceAlias);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,19 +288,20 @@ private async Task<OAuth2Token> EnsureAccessToken(ServiceDetail serviceDetail, O
Dictionary<string, string> parameters = _refreshTokenParametersBuilder.BuildParameters(serviceDetail, refreshToken);

HttpResponseMessage response = await AuthorizationRequestSender.SendOAuth2Request(serviceDetail, parameters);
var responseContent = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
OAuth2Token token = await CreateOAuth2TokenFromResponse(serviceDetail, response);
OAuth2Token token = CreateOAuth2TokenFromResponse(serviceDetail, responseContent);
await StoreOAuth2Token(serviceDetail.Alias, token);
return token;
}
else
{
throw new AuthorizedServiceHttpException(
$"Error response from refresh token request to '{serviceDetail.Alias}'.",
$"Error response from refresh token request to '{serviceDetail.Alias}'. Status: {response.StatusCode}. Reason: {response.ReasonPhrase}. Content: {responseContent}.",
response.StatusCode,
response.ReasonPhrase,
await response.Content.ReadAsStringAsync());
responseContent);
}
}

Expand All @@ -323,19 +324,20 @@ private async Task<OAuth2Token> EnsureExchangeAccessToken(ServiceDetail serviceD
Dictionary<string, string> parameters = _exchangeTokenParametersBuilder.BuildParameters(serviceDetail, accessToken);

HttpResponseMessage response = await AuthorizationRequestSender.SendOAuth2ExchangeRequest(serviceDetail, parameters);
var responseContent = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
OAuth2Token token = await CreateOAuth2TokenFromResponse(serviceDetail, response);
OAuth2Token token = CreateOAuth2TokenFromResponse(serviceDetail, responseContent);
await StoreOAuth2Token(serviceAlias, token);
return token;
}
else
{
throw new AuthorizedServiceHttpException(
$"Error response from exchange access token request to '{serviceAlias}'.",
$"Error response from exchange access token request to '{serviceDetail.Alias}'. Status: {response.StatusCode}. Reason: {response.ReasonPhrase}. Content: {responseContent}.",
response.StatusCode,
response.ReasonPhrase,
await response.Content.ReadAsStringAsync());
responseContent);
}
}

Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "15.1.0",
"version": "15.1.1",
"assemblyVersion": {
"precision": "build"
},
Expand Down

0 comments on commit 757b2b9

Please sign in to comment.