Skip to content

Commit 8edc8b4

Browse files
author
Matej Grochal
committed
pre-pull-request changes
1 parent 47fa481 commit 8edc8b4

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

src/TeaPie/Http/Auth/OAuth2/OAuth2OptionsBuilder.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ private OAuth2OptionsBuilder() { }
1818
public static OAuth2OptionsBuilder Create() => new();
1919

2020
/// <summary>
21-
/// Adds URL to which user should be authenticated.
21+
/// Adds URL on which user should be authenticated.
2222
/// </summary>
23-
/// <param name="oauthUrl">URL to which user should be authenticated.</param>
23+
/// <param name="oauthUrl">URL on which user should be authenticated.</param>
2424
/// <returns>Updated instance of builder.</returns>
2525
public OAuth2OptionsBuilder WithAuthUrl(string oauthUrl)
2626
{
@@ -74,7 +74,6 @@ public OAuth2OptionsBuilder WithUsername(string username)
7474

7575
/// <summary>
7676
/// Adds 'password' parameter with <paramref name="password"/> value.
77-
/// With refresh of the token, variable will be updated.
7877
/// </summary>
7978
/// <param name="password">Value of the parameter with name 'password'.</param>
8079
/// <returns>Updated instance of builder.</returns>
@@ -86,7 +85,7 @@ public OAuth2OptionsBuilder WithPassword(string password)
8685

8786
/// <summary>
8887
/// Access token will be saved to variable named by <paramref name="variableName"/>.
89-
/// With refresh of the token, variable will be updated.
88+
/// With token change, variable is updated accordingly.
9089
/// </summary>
9190
/// <param name="variableName">Name of the variable which will hold access token value.</param>
9291
/// <returns>Updated instance of builder.</returns>
@@ -111,6 +110,10 @@ public OAuth2OptionsBuilder AddParameter(string key, string value)
111110
return this;
112111
}
113112

113+
/// <summary>
114+
/// Creates <see cref="OAuth2Options"/> according to configuration of the builder.
115+
/// </summary>
116+
/// <returns>Options for OAuth2 provider.</returns>
114117
public OAuth2Options Build()
115118
{
116119
CheckRequiredParameters();

src/TeaPie/Http/Auth/OAuth2/OAuth2Provider.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,22 @@ private async Task<string> GetToken()
4242
{
4343
var newToken = await GetTokenFromRequest();
4444
source = ResolveRequestUri();
45-
if (_configuration.AccessTokenVariableName is not null)
46-
{
47-
_variables.SetVariable(_configuration.AccessTokenVariableName, newToken);
48-
}
45+
SetVariableIfNeeded(newToken);
4946
return newToken;
5047
})!;
5148

5249
_logger.LogTrace("{Subject} was fetched from {Source}.", "Access token", source);
5350
return token!;
5451
}
5552

53+
private void SetVariableIfNeeded(string newToken)
54+
{
55+
if (_configuration.AccessTokenVariableName is not null)
56+
{
57+
_variables.SetVariable(_configuration.AccessTokenVariableName, newToken);
58+
}
59+
}
60+
5661
private async Task<string> GetTokenFromRequest()
5762
{
5863
ResolveParameters(out var requestContent, out var requestUri);
@@ -76,11 +81,11 @@ private void LogSendingRequest()
7681
body);
7782
}
7883

79-
private static string ToStringMaskingSecrets(KeyValuePair<string, string> p)
80-
=> p.Key.Contains("password", StringComparison.OrdinalIgnoreCase) ||
81-
p.Key.Contains("secret", StringComparison.OrdinalIgnoreCase)
82-
? $"{p.Key}={new string('*', p.Value.Length)}"
83-
: $"{p.Key}={p.Value}";
84+
private static string ToStringMaskingSecrets(KeyValuePair<string, string> parameter)
85+
=> parameter.Key.Contains("password", StringComparison.OrdinalIgnoreCase) ||
86+
parameter.Key.Contains("secret", StringComparison.OrdinalIgnoreCase)
87+
? $"{parameter.Key}={new string('*', parameter.Value.Length)}"
88+
: $"{parameter.Key}={parameter.Value}";
8489

8590
private void ResolveParameters(out FormUrlEncodedContent requestContent, out string requestUri)
8691
{

src/TeaPie/TeaPie.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
<PackageReference Include="Microsoft.Extensions.Http.Resilience" />
1515
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />
1616
<PackageReference Include="NuGet.Protocol" />
17-
<PackageReference Include="Polly" />
1817
<PackageReference Include="Polly.Core" />
1918
<PackageReference Include="Serilog" />
2019
<PackageReference Include="Serilog.Extensions.Logging" />

0 commit comments

Comments
 (0)