Skip to content

Commit f05b208

Browse files
committed
Added path in examples
1 parent 7f90dff commit f05b208

8 files changed

Lines changed: 16 additions & 15 deletions

File tree

‎SpotifyAPI.Web.Auth/EmbedIOAuthServer.cs‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ public class EmbedIOAuthServer : IAuthServer
1515
public event Func<object, AuthorizationCodeResponse, Task> AuthorizationCodeReceived;
1616
public event Func<object, ImplictGrantResponse, Task> ImplictGrantReceived;
1717

18-
private const string CallbackPath = "/";
1918
private const string AssetsResourcePath = "SpotifyAPI.Web.Auth.Resources.auth_assets";
2019
private const string DefaultResourcePath = "SpotifyAPI.Web.Auth.Resources.default_site";
2120

@@ -62,11 +61,10 @@ public EmbedIOAuthServer(Uri baseUri, int port, Assembly resourceAssembly, strin
6261
return ctx.SendStringAsync("OK", "text/plain", Encoding.UTF8);
6362
}))
6463
.WithEmbeddedResources("/auth_assets", Assembly.GetExecutingAssembly(), AssetsResourcePath)
65-
.WithEmbeddedResources("/", resourceAssembly, resourcePath);
64+
.WithEmbeddedResources(baseUri.AbsolutePath, resourceAssembly, resourcePath);
6665
}
6766

6867
public Uri BaseUri { get; }
69-
public Uri RedirectUri { get => new Uri(BaseUri, CallbackPath); }
7068
public int Port { get; }
7169

7270
public Task Start()
@@ -86,12 +84,10 @@ public Uri BuildLoginUri(LoginRequest request)
8684
{
8785
Ensure.ArgumentNotNull(request, nameof(request));
8886

89-
var callbackUri = new Uri(BaseUri, CallbackPath);
90-
9187
StringBuilder builder = new StringBuilder(SpotifyUrls.Authorize.ToString());
9288
builder.Append($"?client_id={request.ClientId}");
9389
builder.Append($"&response_type={request.ResponseTypeParam.ToString().ToLower()}");
94-
builder.Append($"&redirect_uri={HttpUtility.UrlEncode(callbackUri.ToString())}");
90+
builder.Append($"&redirect_uri={HttpUtility.UrlEncode(BaseUri.ToString())}");
9591
if (!string.IsNullOrEmpty(request.State))
9692
{
9793
builder.Append($"&state={HttpUtility.UrlEncode(request.State)}");

‎SpotifyAPI.Web.Auth/IAuthServer.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ public interface IAuthServer : IDisposable
1414

1515
Uri BuildLoginUri(LoginRequest request);
1616

17-
Uri RedirectUri { get; }
17+
Uri BaseUri { get; }
1818
}
1919
}
File renamed without changes.
File renamed without changes.

‎SpotifyAPI.Web.Auth/Resources/default_site/index.html‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
<title>Spotify Authorization</title>
88
<meta name='viewport' content='width=device-width, initial-scale=1'>
99
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet">
10-
<link href="/main.css" rel="stylesheet">
10+
<link href="/auth_assets/main.css" rel="stylesheet">
1111
<script src="/auth_assets/main.js"></script>
1212
</head>
1313

1414
<body>
1515
<main>
1616
<div class="flex justify-center flex-wrap logo">
1717
<div class="w-1/8">
18-
<img src="logo.svg" width="120" height="120" />
18+
<img src="/auth_assets/logo.svg" width="120" height="120" />
1919
</div>
2020
</div>
2121
<h1 class="text-4xl">Success!</h1>

‎SpotifyAPI.Web.Examples/CLI.CustomHTML/Program.cs‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ public class Program
1717
public static async Task Main()
1818
{
1919
_server = new EmbedIOAuthServer(
20-
new Uri("http://localhost:5000"), 5000, Assembly.GetExecutingAssembly(), "CLI.CustomHTML.Resources.custom_site");
20+
new Uri("http://localhost:5000/callback"),
21+
5000,
22+
Assembly.GetExecutingAssembly(),
23+
"CLI.CustomHTML.Resources.custom_site"
24+
);
2125
await _server.Start();
2226

2327
_server.AuthorizationCodeReceived += OnAuthorizationCodeReceived;
@@ -45,7 +49,7 @@ private static async Task OnAuthorizationCodeReceived(object sender, Authorizati
4549
await _server.Stop();
4650

4751
AuthorizationCodeTokenResponse token = await new OAuthClient().RequestToken(
48-
new AuthorizationCodeTokenRequest(clientId, clientSecret, response.Code, _server.RedirectUri)
52+
new AuthorizationCodeTokenRequest(clientId, clientSecret, response.Code, _server.BaseUri)
4953
);
5054

5155
var config = SpotifyClientConfig.CreateDefault().WithToken(token.AccessToken, token.TokenType);
@@ -54,6 +58,7 @@ private static async Task OnAuthorizationCodeReceived(object sender, Authorizati
5458
var me = await spotify.UserProfile.Current();
5559

5660
Console.WriteLine($"Your E-Mail: {me.Email}");
61+
Environment.Exit(0);
5762
}
5863
}
5964
}

‎SpotifyAPI.Web.Examples/CLI.CustomHTML/Resources/custom_site/index.html‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
<h1>
2424
Authentication successful
2525
</h1>
26-
<p>
26+
<a href="https://bl.ocks.org/mbostock/9539958">
2727
Just an example how to load custom HTML!
28-
</p>
28+
</a>
2929
</body>
3030

3131
<script>

‎SpotifyAPI.Web.Examples/CLI.PersistentConfig/Program.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ private static async Task Start()
6161

6262
private static async Task StartAuthentication()
6363
{
64-
_server = new EmbedIOAuthServer(new Uri("http://localhost:5000"), 5000);
64+
_server = new EmbedIOAuthServer(new Uri("http://localhost:5000/callback"), 5000);
6565
await _server.Start();
6666
_server.AuthorizationCodeReceived += OnAuthorizationCodeReceived;
6767

@@ -85,7 +85,7 @@ private static async Task OnAuthorizationCodeReceived(object sender, Authorizati
8585
{
8686
await _server.Stop();
8787
AuthorizationCodeTokenResponse token = await new OAuthClient().RequestToken(
88-
new AuthorizationCodeTokenRequest(clientId, clientSecret, response.Code, _server.RedirectUri)
88+
new AuthorizationCodeTokenRequest(clientId, clientSecret, response.Code, _server.BaseUri)
8989
);
9090

9191
await File.WriteAllTextAsync(CredentialsPath, JsonConvert.SerializeObject(token));

0 commit comments

Comments
 (0)