Add interfaces for tokens (#499)

* Add interfaces for tokens

* Delete UpgradeLog.htm

* Changed Namespace

Co-authored-by: Jonas Dellinger <jonas@dellinger.dev>
This commit is contained in:
Tim Ittermann 2020-08-26 15:38:00 +02:00 committed by GitHub
parent d20e83f4f5
commit a9c4aba7fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 65 additions and 4 deletions

View File

@ -11,6 +11,10 @@ namespace SpotifyAPI.Web
{ {
private readonly IAPIConnector _apiConnector; private readonly IAPIConnector _apiConnector;
public SpotifyClient(IToken token) :
this(SpotifyClientConfig.CreateDefault(token?.AccessToken ?? throw new ArgumentNullException(nameof(token)), token.TokenType))
{ }
public SpotifyClient(string token, string tokenType = "Bearer") : public SpotifyClient(string token, string tokenType = "Bearer") :
this(SpotifyClientConfig.CreateDefault(token, tokenType)) this(SpotifyClientConfig.CreateDefault(token, tokenType))
{ } { }

View File

@ -2,7 +2,7 @@ using System;
namespace SpotifyAPI.Web namespace SpotifyAPI.Web
{ {
public class AuthorizationCodeRefreshResponse public class AuthorizationCodeRefreshResponse: IUserToken
{ {
public string AccessToken { get; set; } = default!; public string AccessToken { get; set; } = default!;
public string TokenType { get; set; } = default!; public string TokenType { get; set; } = default!;

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
namespace SpotifyAPI.Web namespace SpotifyAPI.Web
{ {
public class AuthorizationCodeTokenResponse public class AuthorizationCodeTokenResponse: IRefreshableToken
{ {
public string AccessToken { get; set; } = default!; public string AccessToken { get; set; } = default!;
public string TokenType { get; set; } = default!; public string TokenType { get; set; } = default!;

View File

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

View File

@ -0,0 +1,13 @@
namespace SpotifyAPI.Web
{
/// <summary>
/// An user token, which can be refreshed
/// </summary>
public interface IRefreshableToken : IUserToken
{
/// <summary>
/// Refresh token
/// </summary>
public string RefreshToken { get; set; }
}
}

View File

@ -0,0 +1,30 @@
using System;
namespace SpotifyAPI.Web
{
/// <summary>
/// A token to access the Spotify API
/// </summary>
public interface IToken
{
/// <summary>
/// Access token string
/// </summary>
public string AccessToken { get; set; }
/// <summary>
/// Type of this token (eg. Bearer)
/// </summary>
public string TokenType { get; set; }
/// <summary>
/// Auto-Initalized to UTC Now
/// </summary>
public DateTime CreatedAt { get; set; }
/// <summary>
/// Is the token still valid?
/// </summary>
public bool IsExpired { get; }
}
}

View File

@ -0,0 +1,13 @@
namespace SpotifyAPI.Web
{
/// <summary>
/// A token which allows you to access the API as user
/// </summary>
public interface IUserToken : IToken
{
/// <summary>
/// Comma-Seperated list of scopes
/// </summary>
public string Scope { get; set; }
}
}

View File

@ -2,7 +2,7 @@ using System;
namespace SpotifyAPI.Web namespace SpotifyAPI.Web
{ {
public class PKCETokenResponse public class PKCETokenResponse: IRefreshableToken
{ {
public string AccessToken { get; set; } = default!; public string AccessToken { get; set; } = default!;
public string TokenType { get; set; } = default!; public string TokenType { get; set; } = default!;