<linkrel="alternate"type="application/rss+xml"href="/SpotifyAPI-NET/news/rss.xml"title="SpotifyAPI-NET Blog RSS Feed">
<linkrel="alternate"type="application/atom+xml"href="/SpotifyAPI-NET/news/atom.xml"title="SpotifyAPI-NET Blog Atom Feed"><titledata-react-helmet="true">Implicit Grant | SpotifyAPI-NET</title><metadata-react-helmet="true"property="og:url"content="https://johnnycrazy.github.io/SpotifyAPI-NET/docs/implicit_grant"><metadata-react-helmet="true"name="docusaurus_locale"content="en"><metadata-react-helmet="true"name="docusaurus_version"content="current"><metadata-react-helmet="true"name="docusaurus_tag"content="docs-default-current"><metadata-react-helmet="true"property="og:title"content="Implicit Grant | SpotifyAPI-NET"><metadata-react-helmet="true"name="description"content="Implicit grant flow is for clients that are implemented entirely using JavaScript and running in the resource owner’s browser. You do not need any server-side code to use it. Rate limits for requests are improved but there is no refresh token provided. This flow is described in RFC-6749."><metadata-react-helmet="true"property="og:description"content="Implicit grant flow is for clients that are implemented entirely using JavaScript and running in the resource owner’s browser. You do not need any server-side code to use it. Rate limits for requests are improved but there is no refresh token provided. This flow is described in RFC-6749."><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/implicit_grant"><linkdata-react-helmet="true"rel="alternate"href="https://johnnycrazy.github.io/SpotifyAPI-NET/docs/implicit_grant"hreflang="en"><linkdata-react-helmet="true"rel="alternate"href="https://johnnycrazy.github.io/SpotifyAPI-NET/docs/implicit_grant"hreflang="x-default"><linkrel="stylesheet"href="/SpotifyAPI-NET/assets/css/styles.fa980c59.css">
</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">// This call requires Spotify.Web.Auth</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">BrowserUtil.Open(uri);</span></div></div></div><buttontype="button"aria-label="Copy code to clipboard"class="copyButton_Ue-o">Copy</button></div></div><p>After the user has logged in and consented your app, your <code>UWP</code> app will receive a callback:</p><divclass="codeBlockContainer_K1bP"><divclass="codeBlockContent_hGly csharp"><divtabindex="0"class="prism-code language-csharp codeBlock_23N8 thin-scrollbar"><divclass="codeBlockLines_39YC"style="color:#bfc7d5;background-color:#292d3e"><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">protected override void OnActivated(IActivatedEventArgs args)</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">{</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> if (args.Kind == ActivationKind.Protocol)</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> {</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> ProtocolActivatedEventArgs eventArgs = args as ProtocolActivatedEventArgs;</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> var publisher = Mvx.IoCProvider.Resolve<ITokenPublisherService>();</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"> // This Uri contains your access token in the Fragment part</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> Console.WriteLine(eventArgs.Uri);</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> }</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">}</span></div></div></div><buttontype="button"aria-label="Copy code to clipboard"class="copyButton_Ue-o">Copy</button></div></div><p>For a real example, have a look at the <ahref="https://github.com/JohnnyCrazy/SpotifyAPI-NET/tree/master/SpotifyAPI.Web.Examples/Example.UWP"target="_blank"rel="noopener noreferrer">Example.UWP</a>, <ahref="https://github.com/JohnnyCrazy/SpotifyAPI-NET/tree/master/SpotifyAPI.Web.Examples/Example.ASP"target="_blank"rel="noopener noreferrer">Example.ASP</a> or <ahref="https://github.com/JohnnyCrazy/SpotifyAPI-NET/tree/master/SpotifyAPI.Web.Examples/Example.ASPBlazor"target="_blank"rel="noopener noreferrer">Example.ASPBlazor</a></p><h1><aaria-hidden="true"tabindex="-1"class="anchor enhancedAnchor_2LWZ"id="using-spotifywebauth"></a>Using Spotify.Web.Auth<aclass="hash-link"href="#using-spotifywebauth"title="Direct link to heading">#</a></h1><p>For cross-platform CLI and desktop apps (non <code>UWP</code> apps), custom protocol handlers are sometimes not an option. The fallback here is a small cross-platform embedded web server running on <code>http://localhost:5000</code> serving JavaScript. The JavaScript will parse the fragment part of the URI and sends a request to the web server in the background. The web server then notifies your appliciation via an event.</p><divclass="codeBlockContainer_K1bP"><divclass="codeBlockContent_hGly csharp"><divtabindex="0"class="prism-code language-csharp codeBlock_23N8 thin-scrollbar"><divclass="codeBlockLines_39YC"style="color:#bfc7d5;background-color:#292d3e"><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">private static EmbedIOAuthServer _server;</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">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"> // Make sure "http://localhost:5000/callback" is in your spotify application as redirect uri!</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> _server = new EmbedIOAuthServer(new Uri("http://localhost:5000/callback"), 5000);</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> await _server.Start();</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"style="display:inline-block">