2020-05-20 19:59:11 +01:00
|
|
|
using System.Globalization;
|
2020-05-18 10:39:01 +01:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Text;
|
|
|
|
using System.Web;
|
|
|
|
|
|
|
|
namespace SpotifyAPI.Web
|
|
|
|
{
|
|
|
|
public class LoginRequest
|
|
|
|
{
|
|
|
|
public LoginRequest(Uri redirectUri, string clientId, ResponseType responseType)
|
|
|
|
{
|
|
|
|
Ensure.ArgumentNotNull(redirectUri, nameof(redirectUri));
|
|
|
|
Ensure.ArgumentNotNullOrEmptyString(clientId, nameof(clientId));
|
|
|
|
|
|
|
|
RedirectUri = redirectUri;
|
|
|
|
ClientId = clientId;
|
|
|
|
ResponseTypeParam = responseType;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Uri RedirectUri { get; }
|
|
|
|
public ResponseType ResponseTypeParam { get; }
|
|
|
|
public string ClientId { get; }
|
2020-05-25 17:00:38 +01:00
|
|
|
public string? State { get; set; }
|
|
|
|
public ICollection<string>? Scope { get; set; }
|
2020-05-18 10:39:01 +01:00
|
|
|
public bool? ShowDialog { get; set; }
|
2020-08-06 19:48:49 +01:00
|
|
|
public string? CodeChallengeMethod { get; set; }
|
|
|
|
public string? CodeChallenge { get; set; }
|
2020-05-18 10:39:01 +01:00
|
|
|
|
|
|
|
public Uri ToUri()
|
|
|
|
{
|
|
|
|
StringBuilder builder = new StringBuilder(SpotifyUrls.Authorize.ToString());
|
|
|
|
builder.Append($"?client_id={ClientId}");
|
2020-05-20 19:59:11 +01:00
|
|
|
builder.Append($"&response_type={ResponseTypeParam.ToString().ToLower(CultureInfo.InvariantCulture)}");
|
2020-05-18 10:39:01 +01:00
|
|
|
builder.Append($"&redirect_uri={HttpUtility.UrlEncode(RedirectUri.ToString())}");
|
|
|
|
if (!string.IsNullOrEmpty(State))
|
|
|
|
{
|
|
|
|
builder.Append($"&state={HttpUtility.UrlEncode(State)}");
|
|
|
|
}
|
|
|
|
if (Scope != null)
|
|
|
|
{
|
|
|
|
builder.Append($"&scope={HttpUtility.UrlEncode(string.Join(" ", Scope))}");
|
|
|
|
}
|
|
|
|
if (ShowDialog != null)
|
|
|
|
{
|
|
|
|
builder.Append($"&show_dialog={ShowDialog.Value}");
|
|
|
|
}
|
2020-08-06 19:48:49 +01:00
|
|
|
if (CodeChallenge != null)
|
|
|
|
{
|
|
|
|
builder.Append($"&code_challenge={CodeChallenge}");
|
|
|
|
}
|
|
|
|
if (CodeChallengeMethod != null)
|
|
|
|
{
|
|
|
|
builder.Append($"&code_challenge_method={CodeChallengeMethod}");
|
|
|
|
}
|
2020-05-18 10:39:01 +01:00
|
|
|
|
|
|
|
return new Uri(builder.ToString());
|
|
|
|
}
|
|
|
|
|
|
|
|
public enum ResponseType
|
|
|
|
{
|
|
|
|
Code,
|
|
|
|
Token
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-25 17:00:38 +01:00
|
|
|
|