Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { SpotifyApi } from '@sspenst/spotify-web-api';

// Choose one of the following:
const sdk = SpotifyApi.withUserAuthorization("client-id", "http://127.0.0.1:3000", ["scope1", "scope2"]);
const sdk = SpotifyApi.withClientCredentials("client-id", "secret", ["scope1", "scope2"]);
const sdk = SpotifyApi.withClientCredentials("client-id", "secret");
```

Each of these factory methods will return a `SpotifyApi` instance, which you can use to make requests to the Spotify Web API.
Expand Down
8 changes: 4 additions & 4 deletions example_node/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example_node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"author": "",
"license": "ISC",
"dependencies": {
"dotenv": "^16.6.1"
"dotenv": "^17.2.3"
}
}
2 changes: 1 addition & 1 deletion src/SpotifyApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe("SpotifyAPI Instance", () => {
});

it("can create an instance with the client credentials strategy configured", async () => {
const sut = SpotifyApi.withClientCredentials("client-id", "secret", ["scope1", "scope2"]);
const sut = SpotifyApi.withClientCredentials("client-id", "secret");
expect(sut["authenticationStrategy"].constructor.name).toBe(ClientCredentialsStrategy.name);
});

Expand Down
4 changes: 2 additions & 2 deletions src/SpotifyApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ export class SpotifyApi {
return new SpotifyApi(strategy, config);
}

public static withClientCredentials(clientId: string, clientSecret: string, scopes: string[] = [], config?: SdkOptions): SpotifyApi {
const strategy = new ClientCredentialsStrategy(clientId, clientSecret, scopes);
public static withClientCredentials(clientId: string, clientSecret: string, config?: SdkOptions): SpotifyApi {
const strategy = new ClientCredentialsStrategy(clientId, clientSecret);
return new SpotifyApi(strategy, config);
}

Expand Down
9 changes: 1 addition & 8 deletions src/auth/ClientCredentialsStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export default class ClientCredentialsStrategy implements IAuthStrategy {
constructor(
private clientId: string,
private clientSecret: string,
private scopes: string[] = []
) {
}

Expand Down Expand Up @@ -45,12 +44,6 @@ export default class ClientCredentialsStrategy implements IAuthStrategy {
}

private async getTokenFromApi(): Promise<AccessToken> {
const options = {
grant_type: 'client_credentials',
scope: this.scopes.join(' ')
} as any;

const bodyAsString = Object.keys(options).map(key => key + '=' + options[key]).join('&');
const hasBuffer = typeof Buffer !== 'undefined';
const credentials = `${this.clientId}:${this.clientSecret}`;

Expand All @@ -64,7 +57,7 @@ export default class ClientCredentialsStrategy implements IAuthStrategy {
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": `Basic ${basicAuth}`
},
body: bodyAsString
body: "grant_type=client_credentials"
});

if (result.status !== 200) {
Expand Down