Rename all Credentials* classes to correct ClientCredentials*

This commit is contained in:
Jonas Dellinger 2020-06-07 13:28:49 +02:00
parent 025571840c
commit ec08baf80b
4 changed files with 15 additions and 12 deletions

View File

@ -7,10 +7,8 @@ namespace SpotifyAPI.Web
/// This Authenticator requests new credentials token on demand and stores them into memory.
/// It is unable to query user specifc details.
/// </summary>
public class CredentialsAuthenticator : IAuthenticator
public class ClientCredentialsAuthenticator : IAuthenticator
{
private CredentialsTokenResponse? _token;
/// <summary>
/// Initiate a new instance. The first token will be fetched when the first API call occurs
/// </summary>
@ -20,15 +18,20 @@ namespace SpotifyAPI.Web
/// <param name="clientSecret">
/// The ClientID, defined in a spotify application in your Spotify Developer Dashboard
/// </param>
public CredentialsAuthenticator(string clientId, string clientSecret)
public ClientCredentialsAuthenticator(string clientId, string clientSecret) : this(clientId, clientSecret, null) { }
public ClientCredentialsAuthenticator(string clientId, string clientSecret, ClientCredentialsTokenResponse? token)
{
Ensure.ArgumentNotNullOrEmptyString(clientId, nameof(clientId));
Ensure.ArgumentNotNullOrEmptyString(clientSecret, nameof(clientSecret));
ClientId = clientId;
ClientSecret = clientSecret;
Token = token;
}
public ClientCredentialsTokenResponse? Token { get; private set; }
/// <summary>
/// The ClientID, defined in a spotify application in your Spotify Developer Dashboard
/// </summary>
@ -43,13 +46,13 @@ namespace SpotifyAPI.Web
{
Ensure.ArgumentNotNull(request, nameof(request));
if (_token == null || _token.IsExpired)
if (Token == null || Token.IsExpired)
{
var tokenRequest = new ClientCredentialsRequest(ClientId, ClientSecret);
_token = await OAuthClient.RequestToken(tokenRequest, apiConnector).ConfigureAwait(false);
Token = await OAuthClient.RequestToken(tokenRequest, apiConnector).ConfigureAwait(false);
}
request.Headers["Authorization"] = $"{_token.TokenType} {_token.AccessToken}";
request.Headers["Authorization"] = $"{Token.TokenType} {Token.AccessToken}";
}
}
}

View File

@ -16,7 +16,7 @@ namespace SpotifyAPI.Web
/// https://developer.spotify.com/documentation/general/guides/authorization-guide/#client-credentials-flow
/// </remarks>
/// <returns></returns>
Task<CredentialsTokenResponse> RequestToken(ClientCredentialsRequest request);
Task<ClientCredentialsTokenResponse> RequestToken(ClientCredentialsRequest request);
/// <summary>
/// Refresh an already received token via Authorization Code Auth

View File

@ -24,7 +24,7 @@ namespace SpotifyAPI.Web
/// https://developer.spotify.com/documentation/general/guides/authorization-guide/#client-credentials-flow
/// </remarks>
/// <returns></returns>1
public Task<CredentialsTokenResponse> RequestToken(ClientCredentialsRequest request)
public Task<ClientCredentialsTokenResponse> RequestToken(ClientCredentialsRequest request)
{
return RequestToken(request, API);
}
@ -118,7 +118,7 @@ namespace SpotifyAPI.Web
#pragma warning restore CA2000
}
public static Task<CredentialsTokenResponse> RequestToken(
public static Task<ClientCredentialsTokenResponse> RequestToken(
ClientCredentialsRequest request, IAPIConnector apiConnector
)
{
@ -130,7 +130,7 @@ namespace SpotifyAPI.Web
new KeyValuePair<string, string>("grant_type", "client_credentials")
};
return SendOAuthRequest<CredentialsTokenResponse>(apiConnector, form, request.ClientId, request.ClientSecret);
return SendOAuthRequest<ClientCredentialsTokenResponse>(apiConnector, form, request.ClientId, request.ClientSecret);
}
public static Task<AuthorizationCodeRefreshResponse> RequestToken(

View File

@ -1,7 +1,7 @@
using System;
namespace SpotifyAPI.Web
{
public class CredentialsTokenResponse
public class ClientCredentialsTokenResponse
{
public string AccessToken { get; set; } = default!;
public string TokenType { get; set; } = default!;