You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> The authorization code flow with PKCE is the best option for mobile and desktop applications where it is unsafe to store your client secret. It provides your app with an access token that can be refreshed. For further information about this flow, see IETF RFC-7636.
7
+
8
+
## Generating Challenge & Verifier
9
+
10
+
For every authentation request, a verify code and its challenge code needs to be generated. The class `PKCEUtil` can be used to generate those, either with random generated or self supplied values:
11
+
12
+
```csharp
13
+
// Generates a secure random verifier of length 100 and its challenge
14
+
var (verifier, challenge) =PKCEUtil.GenerateCodes();
15
+
16
+
// Generates a secure random verifier of length 120 and its challenge
17
+
var (verifier, challenge) =PKCEUtil.GenerateCodes(120);
18
+
19
+
// Returns the passed string and its challenge (Make sure it's random and is long enough)
20
+
var (verifier, challenge) =PKCEUtil.GenerateCodes("YourSecureRandomString");
21
+
```
22
+
23
+
## Generating Login URI
24
+
25
+
Like most auth flows, you'll need to redirect your user to spotify's servers so he is able to grant access to your application:
26
+
27
+
```csharp
28
+
// Make sure "http://localhost:5000/callback" is in your applications redirect URIs!
// Redirect user to uri via your favorite web-server
41
+
```
42
+
43
+
When the user is redirected to the generated uri, he will have to login with his spotify account and confirm, that your application wants to access his user data. Once confirmed, he will be redirect to `http://localhost:5000/callback` and a `code` parameter is attached to the query. The redirect URI can also contain a custom protocol paired with UWP App Custom Protocol handler. This received `code` has to be exchanged for an `access_token` and `refresh_token`:
44
+
45
+
```csharp
46
+
// This method should be called from your web-server when the user visits "http://localhost:5000/callback"
47
+
publicTaskGetCallback(stringcode)
48
+
{
49
+
// Note that we use the verifier calculated above!
0 commit comments