mirror of
https://github.com/Sarsoo/Spotify.NET.git
synced 2024-12-24 06:56:27 +00:00
143 lines
18 KiB
HTML
143 lines
18 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en-US">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
<title>AutorizationCodeAuth | SpotifyAPI-NET</title>
|
|
<meta name="description" content="🔉 An API for the Spotify-Client and the Spotify Web API, written in C#/.NET">
|
|
<meta name="generator" content="VuePress 1.4.0">
|
|
|
|
|
|
<link rel="preload" href="/SpotifyAPI-NET/assets/css/0.styles.82abfbf9.css" as="style"><link rel="preload" href="/SpotifyAPI-NET/assets/js/app.99b9075e.js" as="script"><link rel="preload" href="/SpotifyAPI-NET/assets/js/2.31113494.js" as="script"><link rel="preload" href="/SpotifyAPI-NET/assets/js/6.66d7c2fe.js" as="script"><link rel="prefetch" href="/SpotifyAPI-NET/assets/js/10.d143fded.js"><link rel="prefetch" href="/SpotifyAPI-NET/assets/js/11.8fa35ecc.js"><link rel="prefetch" href="/SpotifyAPI-NET/assets/js/12.a5a62d6e.js"><link rel="prefetch" href="/SpotifyAPI-NET/assets/js/13.8b5c9b44.js"><link rel="prefetch" href="/SpotifyAPI-NET/assets/js/14.c0f35def.js"><link rel="prefetch" href="/SpotifyAPI-NET/assets/js/15.cfa7a58a.js"><link rel="prefetch" href="/SpotifyAPI-NET/assets/js/16.49c1b208.js"><link rel="prefetch" href="/SpotifyAPI-NET/assets/js/17.b0060b8b.js"><link rel="prefetch" href="/SpotifyAPI-NET/assets/js/18.6bcd5883.js"><link rel="prefetch" href="/SpotifyAPI-NET/assets/js/19.a6196abf.js"><link rel="prefetch" href="/SpotifyAPI-NET/assets/js/20.540a6f36.js"><link rel="prefetch" href="/SpotifyAPI-NET/assets/js/21.956153ac.js"><link rel="prefetch" href="/SpotifyAPI-NET/assets/js/22.a4edf47c.js"><link rel="prefetch" href="/SpotifyAPI-NET/assets/js/23.75c8c4df.js"><link rel="prefetch" href="/SpotifyAPI-NET/assets/js/24.4b98f02a.js"><link rel="prefetch" href="/SpotifyAPI-NET/assets/js/25.67423a61.js"><link rel="prefetch" href="/SpotifyAPI-NET/assets/js/26.fd03eb58.js"><link rel="prefetch" href="/SpotifyAPI-NET/assets/js/3.7ef0fbfe.js"><link rel="prefetch" href="/SpotifyAPI-NET/assets/js/4.2f270ddd.js"><link rel="prefetch" href="/SpotifyAPI-NET/assets/js/5.14f2fea3.js"><link rel="prefetch" href="/SpotifyAPI-NET/assets/js/7.830f290b.js"><link rel="prefetch" href="/SpotifyAPI-NET/assets/js/8.9cb2269f.js"><link rel="prefetch" href="/SpotifyAPI-NET/assets/js/9.1df16d8e.js">
|
|
<link rel="stylesheet" href="/SpotifyAPI-NET/assets/css/0.styles.82abfbf9.css">
|
|
</head>
|
|
<body>
|
|
<div id="app" data-server-rendered="true"><div class="theme-container no-sidebar"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/SpotifyAPI-NET/" class="home-link router-link-active"><!----> <span class="site-name">SpotifyAPI-NET</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/SpotifyAPI-NET/" class="nav-link">
|
|
Home
|
|
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="SpotifyAPI.Web" class="dropdown-title"><span class="title">SpotifyAPI.Web</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/SpotifyAPI-NET/web/getting_started.html" class="nav-link">
|
|
Getting Started
|
|
</a></li><li class="dropdown-item"><!----> <a href="/SpotifyAPI-NET/web/examples.html" class="nav-link">
|
|
Examples
|
|
</a></li><li class="dropdown-item"><!----> <a href="/SpotifyAPI-NET/web/proxy.html" class="nav-link">
|
|
Proxy
|
|
</a></li><li class="dropdown-item"><!----> <a href="/SpotifyAPI-NET/web/albums.html" class="nav-link">
|
|
- Albums
|
|
</a></li><li class="dropdown-item"><!----> <a href="/SpotifyAPI-NET/web/artists.html" class="nav-link">
|
|
- Artists
|
|
</a></li><li class="dropdown-item"><!----> <a href="/SpotifyAPI-NET/web/browse.html" class="nav-link">
|
|
- Browse
|
|
</a></li><li class="dropdown-item"><!----> <a href="/SpotifyAPI-NET/web/follow.html" class="nav-link">
|
|
- Follow
|
|
</a></li><li class="dropdown-item"><!----> <a href="/SpotifyAPI-NET/web/library.html" class="nav-link">
|
|
- Library
|
|
</a></li><li class="dropdown-item"><!----> <a href="/SpotifyAPI-NET/web/personalization.html" class="nav-link">
|
|
- Personalization
|
|
</a></li><li class="dropdown-item"><!----> <a href="/SpotifyAPI-NET/web/player.html" class="nav-link">
|
|
- Player
|
|
</a></li><li class="dropdown-item"><!----> <a href="/SpotifyAPI-NET/web/playlists.html" class="nav-link">
|
|
- Playlists
|
|
</a></li><li class="dropdown-item"><!----> <a href="/SpotifyAPI-NET/web/profiles.html" class="nav-link">
|
|
- Profiles
|
|
</a></li><li class="dropdown-item"><!----> <a href="/SpotifyAPI-NET/web/search.html" class="nav-link">
|
|
- Search
|
|
</a></li><li class="dropdown-item"><!----> <a href="/SpotifyAPI-NET/web/tracks.html" class="nav-link">
|
|
- Tracks
|
|
</a></li><li class="dropdown-item"><!----> <a href="/SpotifyAPI-NET/web/utils.html" class="nav-link">
|
|
Utilities
|
|
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="SpotifyAPI.Auth" class="dropdown-title"><span class="title">SpotifyAPI.Auth</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/SpotifyAPI-NET/auth/getting_started.html" class="nav-link">
|
|
Getting Started
|
|
</a></li><li class="dropdown-item"><!----> <a href="/SpotifyAPI-NET/auth/implicit_grant.html" class="nav-link">
|
|
- ImplicitGrantAuth
|
|
</a></li><li class="dropdown-item"><!----> <a href="/SpotifyAPI-NET/auth/token_swap.html" class="nav-link">
|
|
- TokenSwapAuth
|
|
</a></li><li class="dropdown-item"><!----> <a href="/SpotifyAPI-NET/auth/authorization_code.html" class="nav-link router-link-exact-active router-link-active">
|
|
- AutorizationCodeAuth
|
|
</a></li><li class="dropdown-item"><!----> <a href="/SpotifyAPI-NET/auth/client_credentials.html" class="nav-link">
|
|
- ClientCredentialsAuth
|
|
</a></li></ul></div></div> <a href="https://github.com/JohnnyCrazy/SpotifyAPI-NET" target="_blank" rel="noopener noreferrer" class="repo-link">
|
|
🚀 GitHub
|
|
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/SpotifyAPI-NET/" class="nav-link">
|
|
Home
|
|
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="SpotifyAPI.Web" class="dropdown-title"><span class="title">SpotifyAPI.Web</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/SpotifyAPI-NET/web/getting_started.html" class="nav-link">
|
|
Getting Started
|
|
</a></li><li class="dropdown-item"><!----> <a href="/SpotifyAPI-NET/web/examples.html" class="nav-link">
|
|
Examples
|
|
</a></li><li class="dropdown-item"><!----> <a href="/SpotifyAPI-NET/web/proxy.html" class="nav-link">
|
|
Proxy
|
|
</a></li><li class="dropdown-item"><!----> <a href="/SpotifyAPI-NET/web/albums.html" class="nav-link">
|
|
- Albums
|
|
</a></li><li class="dropdown-item"><!----> <a href="/SpotifyAPI-NET/web/artists.html" class="nav-link">
|
|
- Artists
|
|
</a></li><li class="dropdown-item"><!----> <a href="/SpotifyAPI-NET/web/browse.html" class="nav-link">
|
|
- Browse
|
|
</a></li><li class="dropdown-item"><!----> <a href="/SpotifyAPI-NET/web/follow.html" class="nav-link">
|
|
- Follow
|
|
</a></li><li class="dropdown-item"><!----> <a href="/SpotifyAPI-NET/web/library.html" class="nav-link">
|
|
- Library
|
|
</a></li><li class="dropdown-item"><!----> <a href="/SpotifyAPI-NET/web/personalization.html" class="nav-link">
|
|
- Personalization
|
|
</a></li><li class="dropdown-item"><!----> <a href="/SpotifyAPI-NET/web/player.html" class="nav-link">
|
|
- Player
|
|
</a></li><li class="dropdown-item"><!----> <a href="/SpotifyAPI-NET/web/playlists.html" class="nav-link">
|
|
- Playlists
|
|
</a></li><li class="dropdown-item"><!----> <a href="/SpotifyAPI-NET/web/profiles.html" class="nav-link">
|
|
- Profiles
|
|
</a></li><li class="dropdown-item"><!----> <a href="/SpotifyAPI-NET/web/search.html" class="nav-link">
|
|
- Search
|
|
</a></li><li class="dropdown-item"><!----> <a href="/SpotifyAPI-NET/web/tracks.html" class="nav-link">
|
|
- Tracks
|
|
</a></li><li class="dropdown-item"><!----> <a href="/SpotifyAPI-NET/web/utils.html" class="nav-link">
|
|
Utilities
|
|
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="SpotifyAPI.Auth" class="dropdown-title"><span class="title">SpotifyAPI.Auth</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/SpotifyAPI-NET/auth/getting_started.html" class="nav-link">
|
|
Getting Started
|
|
</a></li><li class="dropdown-item"><!----> <a href="/SpotifyAPI-NET/auth/implicit_grant.html" class="nav-link">
|
|
- ImplicitGrantAuth
|
|
</a></li><li class="dropdown-item"><!----> <a href="/SpotifyAPI-NET/auth/token_swap.html" class="nav-link">
|
|
- TokenSwapAuth
|
|
</a></li><li class="dropdown-item"><!----> <a href="/SpotifyAPI-NET/auth/authorization_code.html" class="nav-link router-link-exact-active router-link-active">
|
|
- AutorizationCodeAuth
|
|
</a></li><li class="dropdown-item"><!----> <a href="/SpotifyAPI-NET/auth/client_credentials.html" class="nav-link">
|
|
- ClientCredentialsAuth
|
|
</a></li></ul></div></div> <a href="https://github.com/JohnnyCrazy/SpotifyAPI-NET" target="_blank" rel="noopener noreferrer" class="repo-link">
|
|
🚀 GitHub
|
|
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></nav> <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>AutorizationCodeAuth</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/SpotifyAPI-NET/auth/authorization_code.html#token-refresh" class="sidebar-link">Token Refresh</a></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="autorizationcodeauth"><a href="#autorizationcodeauth" aria-hidden="true" class="header-anchor">#</a> AutorizationCodeAuth</h1> <p>This way is <strong>not recommended</strong> for client-side apps and requires server-side code to run securely.
|
|
With this approach, you first get a code which you need to trade against the access-token.
|
|
In this exchange you need to provide your Client-Secret and because of that it's not recommended.
|
|
A good thing about this method: You can always refresh your token, without having the user to auth it again.</p> <p>More info: <a href="https://developer.spotify.com/documentation/general/guides/authorization-guide/#authorization-code-flow" target="_blank" rel="noopener noreferrer">here<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></p> <div class="language-csharp extra-class"><pre class="language-csharp"><code><span class="token keyword">static</span> <span class="token keyword">async</span> <span class="token keyword">void</span> <span class="token function">Main</span><span class="token punctuation">(</span><span class="token keyword">string</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span>
|
|
<span class="token punctuation">{</span>
|
|
<span class="token class-name">AuthorizationCodeAuth</span> auth <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">AuthorizationCodeAuth</span><span class="token punctuation">(</span>
|
|
_clientId<span class="token punctuation">,</span>
|
|
_secretId<span class="token punctuation">,</span>
|
|
<span class="token string">"http://localhost:4002"</span><span class="token punctuation">,</span>
|
|
<span class="token string">"http://localhost:4002"</span><span class="token punctuation">,</span>
|
|
Scope<span class="token punctuation">.</span>PlaylistReadPrivate <span class="token operator">|</span> Scope<span class="token punctuation">.</span>PlaylistReadCollaborative
|
|
<span class="token punctuation">)</span><span class="token punctuation">;</span>
|
|
|
|
auth<span class="token punctuation">.</span>AuthReceived <span class="token operator">+=</span> <span class="token keyword">async</span> <span class="token punctuation">(</span>sender<span class="token punctuation">,</span> payload<span class="token punctuation">)</span> <span class="token operator">=></span>
|
|
<span class="token punctuation">{</span>
|
|
auth<span class="token punctuation">.</span><span class="token function">Stop</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
|
<span class="token class-name">Token</span> token <span class="token operator">=</span> <span class="token keyword">await</span> auth<span class="token punctuation">.</span><span class="token function">ExchangeCode</span><span class="token punctuation">(</span>payload<span class="token punctuation">.</span>Code<span class="token punctuation">)</span><span class="token punctuation">;</span>
|
|
<span class="token class-name">SpotifyWebAPI</span> api <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">SpotifyWebAPI</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|
<span class="token punctuation">{</span>
|
|
TokenType <span class="token operator">=</span> token<span class="token punctuation">.</span>TokenType<span class="token punctuation">,</span>
|
|
AccessToken <span class="token operator">=</span> token<span class="token punctuation">.</span>AccessToken
|
|
<span class="token punctuation">}</span><span class="token punctuation">;</span>
|
|
<span class="token comment">// Do requests with API client</span>
|
|
<span class="token punctuation">}</span><span class="token punctuation">;</span>
|
|
auth<span class="token punctuation">.</span><span class="token function">Start</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Starts an internal HTTP Server</span>
|
|
auth<span class="token punctuation">.</span><span class="token function">OpenBrowser</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
|
<span class="token punctuation">}</span>
|
|
</code></pre></div><h2 id="token-refresh"><a href="#token-refresh" aria-hidden="true" class="header-anchor">#</a> Token Refresh</h2> <p>Once the <code>AccessToken</code> is expired, you can use your <code>RefreshToken</code> to get a new one.
|
|
In this procedure, no HTTP Server is needed in the background and a single HTTP Request is made.</p> <div class="language-csharp extra-class"><pre class="language-csharp"><code><span class="token comment">// Auth code from above</span>
|
|
|
|
<span class="token keyword">if</span><span class="token punctuation">(</span>token<span class="token punctuation">.</span><span class="token function">IsExpired</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
|
|
<span class="token punctuation">{</span>
|
|
<span class="token class-name">Token</span> newToken <span class="token operator">=</span> <span class="token keyword">await</span> auth<span class="token punctuation">.</span><span class="token function">RefreshToken</span><span class="token punctuation">(</span>token<span class="token punctuation">.</span>RefreshToken<span class="token punctuation">)</span><span class="token punctuation">;</span>
|
|
api<span class="token punctuation">.</span>AccessToken <span class="token operator">=</span> newToken<span class="token punctuation">.</span><span class="token class-name">AccessToken</span>
|
|
api<span class="token punctuation">.</span>TokenType <span class="token operator">=</span> newToken<span class="token punctuation">.</span>TokenType
|
|
<span class="token punctuation">}</span>
|
|
</code></pre></div></div> <footer class="page-edit"><div class="edit-link"><a href="https://github.com/JohnnyCrazy/SpotifyAPI-NET/edit/master/SpotifyAPI.Docs/docs/auth/authorization_code.md" target="_blank" rel="noopener noreferrer">Help us improve this page!</a> <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></div> <div class="last-updated"><span class="prefix">Last Updated:</span> <span class="time">4/22/2020, 7:16:42 AM</span></div></footer> <!----> </main></div><div class="global-ui"></div></div>
|
|
<script src="/SpotifyAPI-NET/assets/js/app.99b9075e.js" defer></script><script src="/SpotifyAPI-NET/assets/js/2.31113494.js" defer></script><script src="/SpotifyAPI-NET/assets/js/6.66d7c2fe.js" defer></script>
|
|
</body>
|
|
</html>
|