Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[csharp] Add scope for oauth2 #19175

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ namespace {{packageName}}.Client
configuration.OAuthTokenUrl,
configuration.OAuthClientId,
configuration.OAuthClientSecret,
configuration.OAuthScope,
configuration.OAuthFlow,
SerializerSettings,
configuration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,12 @@ namespace {{packageName}}.Client
/// <value>The OAuth Client Secret.</value>
public virtual string OAuthClientSecret { get; set; }

/// <summary>
/// Gets or sets the client scope for OAuth2 authentication.
/// </summary>
/// <value>The OAuth Client Scope.</value>
public virtual string{{nrt?}} OAuthScope { get; set; }

/// <summary>
/// Gets or sets the flow for OAuth2 authentication.
/// </summary>
Expand Down Expand Up @@ -711,6 +717,7 @@ namespace {{packageName}}.Client
OAuthTokenUrl = second.OAuthTokenUrl ?? first.OAuthTokenUrl,
OAuthClientId = second.OAuthClientId ?? first.OAuthClientId,
OAuthClientSecret = second.OAuthClientSecret ?? first.OAuthClientSecret,
OAuthScope = second.OAuthScope ?? first.OAuthScope,
OAuthFlow = second.OAuthFlow ?? first.OAuthFlow,
{{/hasOAuthMethods}}
{{/useRestSharp}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ namespace {{packageName}}.Client
/// <value>OAuth Client Secret.</value>
string OAuthClientSecret { get; }

/// <summary>
/// Gets the OAuth token scope.
/// </summary>
/// <value>OAuth Token scope.</value>
string{{nrt?}} OAuthScope { get; }

/// <summary>
/// Gets the OAuth flow.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace {{packageName}}.Client.Auth
readonly string _tokenUrl;
readonly string _clientId;
readonly string _clientSecret;
readonly string{{nrt?}} _scope;
readonly string _grantType;
readonly JsonSerializerSettings _serializerSettings;
readonly IReadableConfiguration _configuration;
Expand All @@ -27,13 +28,15 @@ namespace {{packageName}}.Client.Auth
string tokenUrl,
string clientId,
string clientSecret,
string{{nrt?}} scope,
OAuthFlow? flow,
JsonSerializerSettings serializerSettings,
IReadableConfiguration configuration) : base("")
{
_tokenUrl = tokenUrl;
_clientId = clientId;
_clientSecret = clientSecret;
_scope = scope;
_serializerSettings = serializerSettings;
_configuration = configuration;

Expand Down Expand Up @@ -80,6 +83,12 @@ namespace {{packageName}}.Client.Auth
.AddParameter("grant_type", _grantType)
.AddParameter("client_id", _clientId)
.AddParameter("client_secret", _clientSecret);

if (!string.IsNullOrEmpty(_scope))
{
request.AddParameter("scope", _scope);
}

var response = await client.PostAsync<TokenResponse>(request).ConfigureAwait(false);

// RFC6749 - token_type is case insensitive.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ private ApiResponse<T> ExecClient<T>(Func<RestClient, RestResponse<T>> getRespon
configuration.OAuthTokenUrl,
configuration.OAuthClientId,
configuration.OAuthClientSecret,
configuration.OAuthScope,
configuration.OAuthFlow,
SerializerSettings,
configuration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class OAuthAuthenticator : AuthenticatorBase
readonly string _tokenUrl;
readonly string _clientId;
readonly string _clientSecret;
readonly string _scope;
readonly string _grantType;
readonly JsonSerializerSettings _serializerSettings;
readonly IReadableConfiguration _configuration;
Expand All @@ -35,13 +36,15 @@ public OAuthAuthenticator(
string tokenUrl,
string clientId,
string clientSecret,
string scope,
OAuthFlow? flow,
JsonSerializerSettings serializerSettings,
IReadableConfiguration configuration) : base("")
{
_tokenUrl = tokenUrl;
_clientId = clientId;
_clientSecret = clientSecret;
_scope = scope;
_serializerSettings = serializerSettings;
_configuration = configuration;

Expand Down Expand Up @@ -88,6 +91,12 @@ async Task<string> GetToken()
.AddParameter("grant_type", _grantType)
.AddParameter("client_id", _clientId)
.AddParameter("client_secret", _clientSecret);

if (!string.IsNullOrEmpty(_scope))
{
request.AddParameter("scope", _scope);
}

var response = await client.PostAsync<TokenResponse>(request).ConfigureAwait(false);

// RFC6749 - token_type is case insensitive.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,12 @@ public string GetApiKeyWithPrefix(string apiKeyIdentifier)
/// <value>The OAuth Client Secret.</value>
public virtual string OAuthClientSecret { get; set; }

/// <summary>
/// Gets or sets the client scope for OAuth2 authentication.
/// </summary>
/// <value>The OAuth Client Scope.</value>
public virtual string OAuthScope { get; set; }

/// <summary>
/// Gets or sets the flow for OAuth2 authentication.
/// </summary>
Expand Down Expand Up @@ -622,6 +628,7 @@ public static IReadableConfiguration MergeConfigurations(IReadableConfiguration
OAuthTokenUrl = second.OAuthTokenUrl ?? first.OAuthTokenUrl,
OAuthClientId = second.OAuthClientId ?? first.OAuthClientId,
OAuthClientSecret = second.OAuthClientSecret ?? first.OAuthClientSecret,
OAuthScope = second.OAuthScope ?? first.OAuthScope,
OAuthFlow = second.OAuthFlow ?? first.OAuthFlow,
TempFolderPath = second.TempFolderPath ?? first.TempFolderPath,
DateTimeFormat = second.DateTimeFormat ?? first.DateTimeFormat,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public interface IReadableConfiguration
/// <value>OAuth Client Secret.</value>
string OAuthClientSecret { get; }

/// <summary>
/// Gets the OAuth token scope.
/// </summary>
/// <value>OAuth Token scope.</value>
string OAuthScope { get; }

/// <summary>
/// Gets the OAuth flow.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ private ApiResponse<T> ExecClient<T>(Func<RestClient, RestResponse<T>> getRespon
configuration.OAuthTokenUrl,
configuration.OAuthClientId,
configuration.OAuthClientSecret,
configuration.OAuthScope,
configuration.OAuthFlow,
SerializerSettings,
configuration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class OAuthAuthenticator : AuthenticatorBase
readonly string _tokenUrl;
readonly string _clientId;
readonly string _clientSecret;
readonly string? _scope;
readonly string _grantType;
readonly JsonSerializerSettings _serializerSettings;
readonly IReadableConfiguration _configuration;
Expand All @@ -35,13 +36,15 @@ public OAuthAuthenticator(
string tokenUrl,
string clientId,
string clientSecret,
string? scope,
OAuthFlow? flow,
JsonSerializerSettings serializerSettings,
IReadableConfiguration configuration) : base("")
{
_tokenUrl = tokenUrl;
_clientId = clientId;
_clientSecret = clientSecret;
_scope = scope;
_serializerSettings = serializerSettings;
_configuration = configuration;

Expand Down Expand Up @@ -88,6 +91,12 @@ async Task<string> GetToken()
.AddParameter("grant_type", _grantType)
.AddParameter("client_id", _clientId)
.AddParameter("client_secret", _clientSecret);

if (!string.IsNullOrEmpty(_scope))
{
request.AddParameter("scope", _scope);
}

var response = await client.PostAsync<TokenResponse>(request).ConfigureAwait(false);

// RFC6749 - token_type is case insensitive.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,12 @@ public string GetApiKeyWithPrefix(string apiKeyIdentifier)
/// <value>The OAuth Client Secret.</value>
public virtual string OAuthClientSecret { get; set; }

/// <summary>
/// Gets or sets the client scope for OAuth2 authentication.
/// </summary>
/// <value>The OAuth Client Scope.</value>
public virtual string? OAuthScope { get; set; }

/// <summary>
/// Gets or sets the flow for OAuth2 authentication.
/// </summary>
Expand Down Expand Up @@ -736,6 +742,7 @@ public static IReadableConfiguration MergeConfigurations(IReadableConfiguration
OAuthTokenUrl = second.OAuthTokenUrl ?? first.OAuthTokenUrl,
OAuthClientId = second.OAuthClientId ?? first.OAuthClientId,
OAuthClientSecret = second.OAuthClientSecret ?? first.OAuthClientSecret,
OAuthScope = second.OAuthScope ?? first.OAuthScope,
OAuthFlow = second.OAuthFlow ?? first.OAuthFlow,
HttpSigningConfiguration = second.HttpSigningConfiguration ?? first.HttpSigningConfiguration,
TempFolderPath = second.TempFolderPath ?? first.TempFolderPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public interface IReadableConfiguration
/// <value>OAuth Client Secret.</value>
string OAuthClientSecret { get; }

/// <summary>
/// Gets the OAuth token scope.
/// </summary>
/// <value>OAuth Token scope.</value>
string? OAuthScope { get; }

/// <summary>
/// Gets the OAuth flow.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ private ApiResponse<T> ExecClient<T>(Func<RestClient, RestResponse<T>> getRespon
configuration.OAuthTokenUrl,
configuration.OAuthClientId,
configuration.OAuthClientSecret,
configuration.OAuthScope,
configuration.OAuthFlow,
SerializerSettings,
configuration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class OAuthAuthenticator : AuthenticatorBase
readonly string _tokenUrl;
readonly string _clientId;
readonly string _clientSecret;
readonly string? _scope;
readonly string _grantType;
readonly JsonSerializerSettings _serializerSettings;
readonly IReadableConfiguration _configuration;
Expand All @@ -35,13 +36,15 @@ public OAuthAuthenticator(
string tokenUrl,
string clientId,
string clientSecret,
string? scope,
OAuthFlow? flow,
JsonSerializerSettings serializerSettings,
IReadableConfiguration configuration) : base("")
{
_tokenUrl = tokenUrl;
_clientId = clientId;
_clientSecret = clientSecret;
_scope = scope;
_serializerSettings = serializerSettings;
_configuration = configuration;

Expand Down Expand Up @@ -88,6 +91,12 @@ async Task<string> GetToken()
.AddParameter("grant_type", _grantType)
.AddParameter("client_id", _clientId)
.AddParameter("client_secret", _clientSecret);

if (!string.IsNullOrEmpty(_scope))
{
request.AddParameter("scope", _scope);
}

var response = await client.PostAsync<TokenResponse>(request).ConfigureAwait(false);

// RFC6749 - token_type is case insensitive.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,12 @@ public string GetApiKeyWithPrefix(string apiKeyIdentifier)
/// <value>The OAuth Client Secret.</value>
public virtual string OAuthClientSecret { get; set; }

/// <summary>
/// Gets or sets the client scope for OAuth2 authentication.
/// </summary>
/// <value>The OAuth Client Scope.</value>
public virtual string? OAuthScope { get; set; }

/// <summary>
/// Gets or sets the flow for OAuth2 authentication.
/// </summary>
Expand Down Expand Up @@ -736,6 +742,7 @@ public static IReadableConfiguration MergeConfigurations(IReadableConfiguration
OAuthTokenUrl = second.OAuthTokenUrl ?? first.OAuthTokenUrl,
OAuthClientId = second.OAuthClientId ?? first.OAuthClientId,
OAuthClientSecret = second.OAuthClientSecret ?? first.OAuthClientSecret,
OAuthScope = second.OAuthScope ?? first.OAuthScope,
OAuthFlow = second.OAuthFlow ?? first.OAuthFlow,
HttpSigningConfiguration = second.HttpSigningConfiguration ?? first.HttpSigningConfiguration,
TempFolderPath = second.TempFolderPath ?? first.TempFolderPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public interface IReadableConfiguration
/// <value>OAuth Client Secret.</value>
string OAuthClientSecret { get; }

/// <summary>
/// Gets the OAuth token scope.
/// </summary>
/// <value>OAuth Token scope.</value>
string? OAuthScope { get; }

/// <summary>
/// Gets the OAuth flow.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ private ApiResponse<T> ExecClient<T>(Func<RestClient, RestResponse<T>> getRespon
configuration.OAuthTokenUrl,
configuration.OAuthClientId,
configuration.OAuthClientSecret,
configuration.OAuthScope,
configuration.OAuthFlow,
SerializerSettings,
configuration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class OAuthAuthenticator : AuthenticatorBase
readonly string _tokenUrl;
readonly string _clientId;
readonly string _clientSecret;
readonly string? _scope;
readonly string _grantType;
readonly JsonSerializerSettings _serializerSettings;
readonly IReadableConfiguration _configuration;
Expand All @@ -35,13 +36,15 @@ public OAuthAuthenticator(
string tokenUrl,
string clientId,
string clientSecret,
string? scope,
OAuthFlow? flow,
JsonSerializerSettings serializerSettings,
IReadableConfiguration configuration) : base("")
{
_tokenUrl = tokenUrl;
_clientId = clientId;
_clientSecret = clientSecret;
_scope = scope;
_serializerSettings = serializerSettings;
_configuration = configuration;

Expand Down Expand Up @@ -88,6 +91,12 @@ async Task<string> GetToken()
.AddParameter("grant_type", _grantType)
.AddParameter("client_id", _clientId)
.AddParameter("client_secret", _clientSecret);

if (!string.IsNullOrEmpty(_scope))
{
request.AddParameter("scope", _scope);
}

var response = await client.PostAsync<TokenResponse>(request).ConfigureAwait(false);

// RFC6749 - token_type is case insensitive.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,12 @@ public string GetApiKeyWithPrefix(string apiKeyIdentifier)
/// <value>The OAuth Client Secret.</value>
public virtual string OAuthClientSecret { get; set; }

/// <summary>
/// Gets or sets the client scope for OAuth2 authentication.
/// </summary>
/// <value>The OAuth Client Scope.</value>
public virtual string? OAuthScope { get; set; }

/// <summary>
/// Gets or sets the flow for OAuth2 authentication.
/// </summary>
Expand Down Expand Up @@ -736,6 +742,7 @@ public static IReadableConfiguration MergeConfigurations(IReadableConfiguration
OAuthTokenUrl = second.OAuthTokenUrl ?? first.OAuthTokenUrl,
OAuthClientId = second.OAuthClientId ?? first.OAuthClientId,
OAuthClientSecret = second.OAuthClientSecret ?? first.OAuthClientSecret,
OAuthScope = second.OAuthScope ?? first.OAuthScope,
OAuthFlow = second.OAuthFlow ?? first.OAuthFlow,
HttpSigningConfiguration = second.HttpSigningConfiguration ?? first.HttpSigningConfiguration,
TempFolderPath = second.TempFolderPath ?? first.TempFolderPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public interface IReadableConfiguration
/// <value>OAuth Client Secret.</value>
string OAuthClientSecret { get; }

/// <summary>
/// Gets the OAuth token scope.
/// </summary>
/// <value>OAuth Token scope.</value>
string? OAuthScope { get; }

/// <summary>
/// Gets the OAuth flow.
/// </summary>
Expand Down
Loading
Loading