mirror of
https://github.com/Sarsoo/Spotify.NET.git
synced 2024-12-24 15:06:26 +00:00
Rename all Credentials* classes to correct ClientCredentials*
This commit is contained in:
parent
025571840c
commit
ec08baf80b
@ -7,10 +7,8 @@ namespace SpotifyAPI.Web
|
|||||||
/// This Authenticator requests new credentials token on demand and stores them into memory.
|
/// This Authenticator requests new credentials token on demand and stores them into memory.
|
||||||
/// It is unable to query user specifc details.
|
/// It is unable to query user specifc details.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class CredentialsAuthenticator : IAuthenticator
|
public class ClientCredentialsAuthenticator : IAuthenticator
|
||||||
{
|
{
|
||||||
private CredentialsTokenResponse? _token;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initiate a new instance. The first token will be fetched when the first API call occurs
|
/// Initiate a new instance. The first token will be fetched when the first API call occurs
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -20,15 +18,20 @@ namespace SpotifyAPI.Web
|
|||||||
/// <param name="clientSecret">
|
/// <param name="clientSecret">
|
||||||
/// The ClientID, defined in a spotify application in your Spotify Developer Dashboard
|
/// The ClientID, defined in a spotify application in your Spotify Developer Dashboard
|
||||||
/// </param>
|
/// </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(clientId, nameof(clientId));
|
||||||
Ensure.ArgumentNotNullOrEmptyString(clientSecret, nameof(clientSecret));
|
Ensure.ArgumentNotNullOrEmptyString(clientSecret, nameof(clientSecret));
|
||||||
|
|
||||||
ClientId = clientId;
|
ClientId = clientId;
|
||||||
ClientSecret = clientSecret;
|
ClientSecret = clientSecret;
|
||||||
|
Token = token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ClientCredentialsTokenResponse? Token { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The ClientID, defined in a spotify application in your Spotify Developer Dashboard
|
/// The ClientID, defined in a spotify application in your Spotify Developer Dashboard
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -43,13 +46,13 @@ namespace SpotifyAPI.Web
|
|||||||
{
|
{
|
||||||
Ensure.ArgumentNotNull(request, nameof(request));
|
Ensure.ArgumentNotNull(request, nameof(request));
|
||||||
|
|
||||||
if (_token == null || _token.IsExpired)
|
if (Token == null || Token.IsExpired)
|
||||||
{
|
{
|
||||||
var tokenRequest = new ClientCredentialsRequest(ClientId, ClientSecret);
|
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}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -16,7 +16,7 @@ namespace SpotifyAPI.Web
|
|||||||
/// https://developer.spotify.com/documentation/general/guides/authorization-guide/#client-credentials-flow
|
/// https://developer.spotify.com/documentation/general/guides/authorization-guide/#client-credentials-flow
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<CredentialsTokenResponse> RequestToken(ClientCredentialsRequest request);
|
Task<ClientCredentialsTokenResponse> RequestToken(ClientCredentialsRequest request);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Refresh an already received token via Authorization Code Auth
|
/// Refresh an already received token via Authorization Code Auth
|
||||||
|
@ -24,7 +24,7 @@ namespace SpotifyAPI.Web
|
|||||||
/// https://developer.spotify.com/documentation/general/guides/authorization-guide/#client-credentials-flow
|
/// https://developer.spotify.com/documentation/general/guides/authorization-guide/#client-credentials-flow
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <returns></returns>1
|
/// <returns></returns>1
|
||||||
public Task<CredentialsTokenResponse> RequestToken(ClientCredentialsRequest request)
|
public Task<ClientCredentialsTokenResponse> RequestToken(ClientCredentialsRequest request)
|
||||||
{
|
{
|
||||||
return RequestToken(request, API);
|
return RequestToken(request, API);
|
||||||
}
|
}
|
||||||
@ -118,7 +118,7 @@ namespace SpotifyAPI.Web
|
|||||||
#pragma warning restore CA2000
|
#pragma warning restore CA2000
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Task<CredentialsTokenResponse> RequestToken(
|
public static Task<ClientCredentialsTokenResponse> RequestToken(
|
||||||
ClientCredentialsRequest request, IAPIConnector apiConnector
|
ClientCredentialsRequest request, IAPIConnector apiConnector
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@ -130,7 +130,7 @@ namespace SpotifyAPI.Web
|
|||||||
new KeyValuePair<string, string>("grant_type", "client_credentials")
|
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(
|
public static Task<AuthorizationCodeRefreshResponse> RequestToken(
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
namespace SpotifyAPI.Web
|
namespace SpotifyAPI.Web
|
||||||
{
|
{
|
||||||
public class CredentialsTokenResponse
|
public class ClientCredentialsTokenResponse
|
||||||
{
|
{
|
||||||
public string AccessToken { get; set; } = default!;
|
public string AccessToken { get; set; } = default!;
|
||||||
public string TokenType { get; set; } = default!;
|
public string TokenType { get; set; } = default!;
|
Loading…
Reference in New Issue
Block a user