From f05b208f6aa5b70c9450affeab8a5377a9c6cb91 Mon Sep 17 00:00:00 2001 From: Jonas Dellinger Date: Fri, 15 May 2020 22:02:54 +0200 Subject: [PATCH] Added path in examples --- SpotifyAPI.Web.Auth/EmbedIOAuthServer.cs | 8 ++------ SpotifyAPI.Web.Auth/IAuthServer.cs | 2 +- .../Resources/{default_site => auth_assets}/logo.svg | 0 .../Resources/{default_site => auth_assets}/main.css | 0 SpotifyAPI.Web.Auth/Resources/default_site/index.html | 4 ++-- SpotifyAPI.Web.Examples/CLI.CustomHTML/Program.cs | 9 +++++++-- .../CLI.CustomHTML/Resources/custom_site/index.html | 4 ++-- SpotifyAPI.Web.Examples/CLI.PersistentConfig/Program.cs | 4 ++-- 8 files changed, 16 insertions(+), 15 deletions(-) rename SpotifyAPI.Web.Auth/Resources/{default_site => auth_assets}/logo.svg (100%) rename SpotifyAPI.Web.Auth/Resources/{default_site => auth_assets}/main.css (100%) diff --git a/SpotifyAPI.Web.Auth/EmbedIOAuthServer.cs b/SpotifyAPI.Web.Auth/EmbedIOAuthServer.cs index ee8f710e..542784c5 100644 --- a/SpotifyAPI.Web.Auth/EmbedIOAuthServer.cs +++ b/SpotifyAPI.Web.Auth/EmbedIOAuthServer.cs @@ -15,7 +15,6 @@ namespace SpotifyAPI.Web.Auth public event Func AuthorizationCodeReceived; public event Func 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)}"); diff --git a/SpotifyAPI.Web.Auth/IAuthServer.cs b/SpotifyAPI.Web.Auth/IAuthServer.cs index 6583ad06..311cb5cb 100644 --- a/SpotifyAPI.Web.Auth/IAuthServer.cs +++ b/SpotifyAPI.Web.Auth/IAuthServer.cs @@ -14,6 +14,6 @@ namespace SpotifyAPI.Web.Auth Uri BuildLoginUri(LoginRequest request); - Uri RedirectUri { get; } + Uri BaseUri { get; } } } diff --git a/SpotifyAPI.Web.Auth/Resources/default_site/logo.svg b/SpotifyAPI.Web.Auth/Resources/auth_assets/logo.svg similarity index 100% rename from SpotifyAPI.Web.Auth/Resources/default_site/logo.svg rename to SpotifyAPI.Web.Auth/Resources/auth_assets/logo.svg diff --git a/SpotifyAPI.Web.Auth/Resources/default_site/main.css b/SpotifyAPI.Web.Auth/Resources/auth_assets/main.css similarity index 100% rename from SpotifyAPI.Web.Auth/Resources/default_site/main.css rename to SpotifyAPI.Web.Auth/Resources/auth_assets/main.css diff --git a/SpotifyAPI.Web.Auth/Resources/default_site/index.html b/SpotifyAPI.Web.Auth/Resources/default_site/index.html index c861954c..6c8c7102 100644 --- a/SpotifyAPI.Web.Auth/Resources/default_site/index.html +++ b/SpotifyAPI.Web.Auth/Resources/default_site/index.html @@ -7,7 +7,7 @@ Spotify Authorization - + @@ -15,7 +15,7 @@

Success!

diff --git a/SpotifyAPI.Web.Examples/CLI.CustomHTML/Program.cs b/SpotifyAPI.Web.Examples/CLI.CustomHTML/Program.cs index 460ef6d6..fed15b9c 100644 --- a/SpotifyAPI.Web.Examples/CLI.CustomHTML/Program.cs +++ b/SpotifyAPI.Web.Examples/CLI.CustomHTML/Program.cs @@ -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); } } } diff --git a/SpotifyAPI.Web.Examples/CLI.CustomHTML/Resources/custom_site/index.html b/SpotifyAPI.Web.Examples/CLI.CustomHTML/Resources/custom_site/index.html index 19fad25a..eb693af6 100644 --- a/SpotifyAPI.Web.Examples/CLI.CustomHTML/Resources/custom_site/index.html +++ b/SpotifyAPI.Web.Examples/CLI.CustomHTML/Resources/custom_site/index.html @@ -23,9 +23,9 @@

Authentication successful

-

+ Just an example how to load custom HTML! -

+