<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.834af7f3.css">
</span></span><spanclass="token-line"style="color:#bfc7d5"><spanclass="token plain">// This call requires Spotify.Web.Auth</span></span><spanclass="token-line"style="color:#bfc7d5"><spanclass="token plain">BrowserUtil.Open(uri);</span></span></code></pre><buttontype="button"aria-label="Copy code to clipboard"class="copyButton_Ue-o clean-btn">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"><pretabindex="0"class="prism-code language-csharp codeBlock_23N8 thin-scrollbar"style="color:#bfc7d5;background-color:#292d3e"><codeclass="codeBlockLines_39YC"><spanclass="token-line"style="color:#bfc7d5"><spanclass="token plain">protected override void OnActivated(IActivatedEventArgs args)</span></span><spanclass="token-line"style="color:#bfc7d5"><spanclass="token plain">{</span></span><spanclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> if (args.Kind == ActivationKind.Protocol)</span></span><spanclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> {</span></span><spanclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> ProtocolActivatedEventArgs eventArgs = args as ProtocolActivatedEventArgs;</span></span><spanclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> var publisher = Mvx.IoCProvider.Resolve<ITokenPublisherService>();</span></span><spanclass="token-line"style="color:#bfc7d5"><spanclass="token plain"style="display:inline-block">
</span></span><spanclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> // This Uri contains your access token in the Fragment part</span></span><spanclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> Console.WriteLine(eventArgs.Uri);</span></span><spanclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> }</span></span><spanclass="token-line"style="color:#bfc7d5"><spanclass="token plain">}</span></span></code></pre><buttontype="button"aria-label="Copy code to clipboard"class="copyButton_Ue-o clean-btn">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><header><h1class="h1Heading_27L5">Using Spotify.Web.Auth</h1></header><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"><pretabindex="0"class="prism-code language-csharp codeBlock_23N8 thin-scrollbar"style="color:#bfc7d5;background-color:#292d3e"><codeclass="codeBlockLines_39YC"><spanclass="token-line"style="color:#bfc7d5"><spanclass="token plain">private static EmbedIOAuthServer _server;</span></span><spanclass="token-line"style="color:#bfc7d5"><spanclass="token plain"style="display:inline-block">
</span></span><spanclass="token-line"style="color:#bfc7d5"><spanclass="token plain">public static async Task Main()</span></span><spanclass="token-line"style="color:#bfc7d5"><spanclass="token plain">{</span></span><spanclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> // Make sure "http://localhost:5000/callback" is in your spotify application as redirect uri!</span></span><spanclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> _server = new EmbedIOAuthServer(new Uri("http://localhost:5000/callback"), 5000);</span></span><spanclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> await _server.Start();</span></span><spanclass="token-line"style="color:#bfc7d5"><spanclass="token plain"style="display:inline-block">