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
Copy file name to clipboardExpand all lines: SpotifyAPI.Docs/docs/auth_introduction.md
+7-6Lines changed: 7 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,16 +7,17 @@ import useBaseUrl from '@docusaurus/useBaseUrl';
7
7
8
8
Spotify does not allow unauthorized access to the api. Thus, you need an access token to make requets. This access token can be gathered via multiple schemes, all following the OAuth2 spec. Since it's important to choose the correct scheme for your usecase, make sure you have a grasp of the following terminology/docs:
Since every auth flow also needs an application in the [spotify dashboard](https://developer.spotify.com/dashboard/), make sure you have the necessary values (like `Client Id` and `Client Secret`).
14
14
15
15
Then, continue with the docs of the specific auth flows:
> 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 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 or open a local browser window
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!
`var spotify = new SpotifyClient("YourAccessToken");
15
+
constexampleCode=`var spotify = new SpotifyClient("YourAccessToken");
16
16
17
17
var me = await spotify.UserProfile.Current();
18
18
Console.WriteLine($"Hello there {me.DisplayName}");
@@ -30,7 +30,9 @@ const features = [
30
30
imageUrl: 'img/undraw_preferences_uuo2.svg',
31
31
description: ()=>(
32
32
<>
33
-
<code>SpotifyAPI-NET</code> allows you to quickly integrate with Spotify's Web API by supplying sane configuration defaults from the start. Later on, behaviour can be customized using extensive configuration possibilities.
33
+
<code>SpotifyAPI-NET</code> allows you to quickly integrate with Spotify's Web API by supplying sane
34
+
configuration defaults from the start. Later on, behaviour can be customized using extensive configuration
The Spotify Web API consists of over 74 API calls. <code>SpotifyAPI-NET</code> provides fully typed requests/responses for all of them.
44
+
The Spotify Web API consists of over 74 API calls. <code>SpotifyAPI-NET</code> provides fully typed
45
+
requests/responses for all of them.
43
46
</>
44
47
),
45
48
},
@@ -48,7 +51,8 @@ const features = [
48
51
imageUrl: 'img/undraw_Devices_e67q.svg',
49
52
description: ()=>(
50
53
<>
51
-
With the support of .NET Standard 2.X, <code>SpotifyAPI-NET</code> runs on many platforms, including .NET Core, UWP and Xamarin.Forms (Windows, Android, iOS and Mac)
54
+
With the support of .NET Standard 2.X, <code>SpotifyAPI-NET</code> runs on many platforms, including .NET Core,
55
+
UWP and Xamarin.Forms (Windows, Android, iOS and Mac)
52
56
</>
53
57
),
54
58
},
@@ -57,7 +61,8 @@ const features = [
57
61
imageUrl: 'img/undraw_QA_engineers_dg5p.svg',
58
62
description: ()=>(
59
63
<>
60
-
<code>SpotifyAPI-NET</code> is built on a modular structure, which allows easy testing through mocks and stubs. Learn more by visiting the <Linkto={useBaseUrl('docs/next/testing')}>Testing Guide</Link>
64
+
<code>SpotifyAPI-NET</code> is built on a modular structure, which allows easy testing through mocks and stubs.
65
+
Learn more by visiting the <Linkto={useBaseUrl('docs/next/testing')}>Testing Guide</Link>
61
66
</>
62
67
),
63
68
},
@@ -82,9 +87,7 @@ function Home() {
82
87
constcontext=useDocusaurusContext();
83
88
const{ siteConfig ={}}=context;
84
89
return(
85
-
<Layout
86
-
title={`${siteConfig.title}`}
87
-
description="Documentation for the C# .NET SpotifyAPI-NET Library">
90
+
<Layouttitle={`${siteConfig.title}`}description="Documentation for the C# .NET SpotifyAPI-NET Library">
0 commit comments