<titledata-react-helmet="true">Client Credentials | SpotifyAPI-NET</title><metadata-react-helmet="true"name="docsearch:version"content="next"><metadata-react-helmet="true"name="twitter:card"content="summary_large_image"><metadata-react-helmet="true"property="og:title"content="Client Credentials | SpotifyAPI-NET"><metadata-react-helmet="true"name="description"content="The Client Credentials flow is used in server-to-server authentication."><metadata-react-helmet="true"property="og:description"content="The Client Credentials flow is used in server-to-server authentication."><metadata-react-helmet="true"property="og:url"content="https://johnnycrazy.github.io/SpotifyAPI-NET/docs/next/client_credentials"><linkdata-react-helmet="true"rel="shortcut icon"href="/SpotifyAPI-NET/img/favicon.ico"><linkdata-react-helmet="true"rel="canonical"href="https://johnnycrazy.github.io/SpotifyAPI-NET/docs/next/client_credentials"><linkrel="stylesheet"href="/SpotifyAPI-NET/styles.8a053330.css">
Only endpoints that do not access user information can be accessed.</p></blockquote><p>By supplying your <code>SPOTIFY_CLIENT_ID</code> and <code>SPOTIFY_CLIENT_SECRET</code>, you get an access token.</p><h2><aaria-hidden="true"tabindex="-1"class="anchor enhancedAnchor_ZqCz"id="request-token-once"></a>Request token once<aaria-hidden="true"tabindex="-1"class="hash-link"href="#request-token-once"title="Direct link to heading">#</a></h2><p>To request an access token, build a <code>ClientCredentialsRequest</code> and send it via <code>OAuthClient</code>. This access token will expire after some time and you need to repeat the process.</p><divclass="mdxCodeBlock_iHAB"><divclass="codeBlockContent_32p_"><buttontype="button"aria-label="Copy code to clipboard"class="copyButton_1BYj">Copy</button><divtabindex="0"class="prism-code language-csharp codeBlock_19pQ"><divclass="codeBlockLines_2n9r"style="color:#bfc7d5;background-color:#292d3e"><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">public static async Task Main()</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">{</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> var config = SpotifyClientConfig.CreateDefault();</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"style="display:inline-block">
</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> var request = new ClientCredentialsRequest("CLIENT_ID", "CLIENT_SECRET");</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> var response = await new OAuthClient(config).RequestToken(request);</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"style="display:inline-block">
</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> var spotify = new SpotifyClient(config.WithToken(response.AccessToken));</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">}</span></div></div></div></div></div><h2><aaria-hidden="true"tabindex="-1"class="anchor enhancedAnchor_ZqCz"id="request-token-on-demand"></a>Request Token On-Demand<aaria-hidden="true"tabindex="-1"class="hash-link"href="#request-token-on-demand"title="Direct link to heading">#</a></h2><p>You can also use <code>CredentialsAuthenticator</code>, which will make sure the spotify instance will always have an up-to-date access token by automatically refreshing the token on-demand.</p><divclass="mdxCodeBlock_iHAB"><divclass="codeBlockContent_32p_"><buttontype="button"aria-label="Copy code to clipboard"class="copyButton_1BYj">Copy</button><divtabindex="0"class="prism-code language-csharp codeBlock_19pQ"><divclass="codeBlockLines_2n9r"style="color:#bfc7d5;background-color:#292d3e"><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">public static async Task Main()</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">{</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> var config = SpotifyClientConfig</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> .CreateDefault()</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> .WithAuthenticator(new ClientCredentialsAuthenticator("CLIENT_ID", "CLIENT_SECRET"));</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"style="display:inline-block">