mirror of
https://github.com/Sarsoo/Spotify.NET.git
synced 2024-12-23 14:46:26 +00:00
Added path in examples
This commit is contained in:
parent
7f90dffe79
commit
f05b208f6a
@ -15,7 +15,6 @@ namespace SpotifyAPI.Web.Auth
|
||||
public event Func<object, AuthorizationCodeResponse, Task> AuthorizationCodeReceived;
|
||||
public event Func<object, ImplictGrantResponse, Task> ImplictGrantReceived;
|
||||
|
||||
private const string CallbackPath = "/";
|
||||
private const string AssetsResourcePath = "SpotifyAPI.Web.Auth.Resources.auth_assets";
|
||||
private const string DefaultResourcePath = "SpotifyAPI.Web.Auth.Resources.default_site";
|
||||
|
||||
@ -62,11 +61,10 @@ namespace SpotifyAPI.Web.Auth
|
||||
return ctx.SendStringAsync("OK", "text/plain", Encoding.UTF8);
|
||||
}))
|
||||
.WithEmbeddedResources("/auth_assets", Assembly.GetExecutingAssembly(), AssetsResourcePath)
|
||||
.WithEmbeddedResources("/", resourceAssembly, resourcePath);
|
||||
.WithEmbeddedResources(baseUri.AbsolutePath, resourceAssembly, resourcePath);
|
||||
}
|
||||
|
||||
public Uri BaseUri { get; }
|
||||
public Uri RedirectUri { get => new Uri(BaseUri, CallbackPath); }
|
||||
public int Port { get; }
|
||||
|
||||
public Task Start()
|
||||
@ -86,12 +84,10 @@ namespace SpotifyAPI.Web.Auth
|
||||
{
|
||||
Ensure.ArgumentNotNull(request, nameof(request));
|
||||
|
||||
var callbackUri = new Uri(BaseUri, CallbackPath);
|
||||
|
||||
StringBuilder builder = new StringBuilder(SpotifyUrls.Authorize.ToString());
|
||||
builder.Append($"?client_id={request.ClientId}");
|
||||
builder.Append($"&response_type={request.ResponseTypeParam.ToString().ToLower()}");
|
||||
builder.Append($"&redirect_uri={HttpUtility.UrlEncode(callbackUri.ToString())}");
|
||||
builder.Append($"&redirect_uri={HttpUtility.UrlEncode(BaseUri.ToString())}");
|
||||
if (!string.IsNullOrEmpty(request.State))
|
||||
{
|
||||
builder.Append($"&state={HttpUtility.UrlEncode(request.State)}");
|
||||
|
@ -14,6 +14,6 @@ namespace SpotifyAPI.Web.Auth
|
||||
|
||||
Uri BuildLoginUri(LoginRequest request);
|
||||
|
||||
Uri RedirectUri { get; }
|
||||
Uri BaseUri { get; }
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 51 KiB After Width: | Height: | Size: 51 KiB |
@ -7,7 +7,7 @@
|
||||
<title>Spotify Authorization</title>
|
||||
<meta name='viewport' content='width=device-width, initial-scale=1'>
|
||||
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet">
|
||||
<link href="/main.css" rel="stylesheet">
|
||||
<link href="/auth_assets/main.css" rel="stylesheet">
|
||||
<script src="/auth_assets/main.js"></script>
|
||||
</head>
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
<main>
|
||||
<div class="flex justify-center flex-wrap logo">
|
||||
<div class="w-1/8">
|
||||
<img src="logo.svg" width="120" height="120" />
|
||||
<img src="/auth_assets/logo.svg" width="120" height="120" />
|
||||
</div>
|
||||
</div>
|
||||
<h1 class="text-4xl">Success!</h1>
|
||||
|
@ -17,7 +17,11 @@ namespace CLI.CustomHTML
|
||||
public static async Task Main()
|
||||
{
|
||||
_server = new EmbedIOAuthServer(
|
||||
new Uri("http://localhost:5000"), 5000, Assembly.GetExecutingAssembly(), "CLI.CustomHTML.Resources.custom_site");
|
||||
new Uri("http://localhost:5000/callback"),
|
||||
5000,
|
||||
Assembly.GetExecutingAssembly(),
|
||||
"CLI.CustomHTML.Resources.custom_site"
|
||||
);
|
||||
await _server.Start();
|
||||
|
||||
_server.AuthorizationCodeReceived += OnAuthorizationCodeReceived;
|
||||
@ -45,7 +49,7 @@ namespace CLI.CustomHTML
|
||||
await _server.Stop();
|
||||
|
||||
AuthorizationCodeTokenResponse token = await new OAuthClient().RequestToken(
|
||||
new AuthorizationCodeTokenRequest(clientId, clientSecret, response.Code, _server.RedirectUri)
|
||||
new AuthorizationCodeTokenRequest(clientId, clientSecret, response.Code, _server.BaseUri)
|
||||
);
|
||||
|
||||
var config = SpotifyClientConfig.CreateDefault().WithToken(token.AccessToken, token.TokenType);
|
||||
@ -54,6 +58,7 @@ namespace CLI.CustomHTML
|
||||
var me = await spotify.UserProfile.Current();
|
||||
|
||||
Console.WriteLine($"Your E-Mail: {me.Email}");
|
||||
Environment.Exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,9 +23,9 @@
|
||||
<h1>
|
||||
Authentication successful
|
||||
</h1>
|
||||
<p>
|
||||
<a href="https://bl.ocks.org/mbostock/9539958">
|
||||
Just an example how to load custom HTML!
|
||||
</p>
|
||||
</a>
|
||||
</body>
|
||||
|
||||
<script>
|
||||
|
@ -61,7 +61,7 @@ namespace CLI.PersistentConfig
|
||||
|
||||
private static async Task StartAuthentication()
|
||||
{
|
||||
_server = new EmbedIOAuthServer(new Uri("http://localhost:5000"), 5000);
|
||||
_server = new EmbedIOAuthServer(new Uri("http://localhost:5000/callback"), 5000);
|
||||
await _server.Start();
|
||||
_server.AuthorizationCodeReceived += OnAuthorizationCodeReceived;
|
||||
|
||||
@ -85,7 +85,7 @@ namespace CLI.PersistentConfig
|
||||
{
|
||||
await _server.Stop();
|
||||
AuthorizationCodeTokenResponse token = await new OAuthClient().RequestToken(
|
||||
new AuthorizationCodeTokenRequest(clientId, clientSecret, response.Code, _server.RedirectUri)
|
||||
new AuthorizationCodeTokenRequest(clientId, clientSecret, response.Code, _server.BaseUri)
|
||||
);
|
||||
|
||||
await File.WriteAllTextAsync(CredentialsPath, JsonConvert.SerializeObject(token));
|
||||
|
Loading…
Reference in New Issue
Block a user