@wwdrew/expo-spotify-sdk 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/ExpoSpotifySDK.types.d.ts +7 -3
- package/build/ExpoSpotifySDK.types.d.ts.map +1 -1
- package/build/ExpoSpotifySDK.types.js.map +1 -1
- package/build/index.d.ts +2 -7
- package/build/index.d.ts.map +1 -1
- package/build/index.js.map +1 -1
- package/ios/ExpoSpotifyAuthDelegate.swift +5 -3
- package/package.json +1 -6
- package/server.js +0 -93
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export interface SpotifySession {
|
|
2
|
+
accessToken: string;
|
|
3
|
+
refreshToken: string;
|
|
4
|
+
expirationDate: number;
|
|
5
|
+
isExpired: boolean;
|
|
6
|
+
}
|
|
7
|
+
export type SpotifyScope = "ugc-image-upload" | "user-read-playback-state" | "user-modify-playback-state" | "user-read-currently-playing" | "app-remote-control" | "streaming" | "playlist-read-private" | "playlist-read-collaborative" | "playlist-modify-private" | "playlist-modify-public" | "user-follow-modify" | "user-follow-read" | "user-top-read" | "user-read-recently-played" | "user-library-modify" | "user-library-read" | "user-read-email" | "user-read-private";
|
|
4
8
|
//# sourceMappingURL=ExpoSpotifySDK.types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoSpotifySDK.types.d.ts","sourceRoot":"","sources":["../src/ExpoSpotifySDK.types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"ExpoSpotifySDK.types.d.ts","sourceRoot":"","sources":["../src/ExpoSpotifySDK.types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,MAAM,YAAY,GACpB,kBAAkB,GAClB,0BAA0B,GAC1B,4BAA4B,GAC5B,6BAA6B,GAC7B,oBAAoB,GACpB,WAAW,GACX,uBAAuB,GACvB,6BAA6B,GAC7B,yBAAyB,GACzB,wBAAwB,GACxB,oBAAoB,GACpB,kBAAkB,GAClB,eAAe,GACf,2BAA2B,GAC3B,qBAAqB,GACrB,mBAAmB,GACnB,iBAAiB,GACjB,mBAAmB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoSpotifySDK.types.js","sourceRoot":"","sources":["../src/ExpoSpotifySDK.types.ts"],"names":[],"mappings":"","sourcesContent":["export
|
|
1
|
+
{"version":3,"file":"ExpoSpotifySDK.types.js","sourceRoot":"","sources":["../src/ExpoSpotifySDK.types.ts"],"names":[],"mappings":"","sourcesContent":["export interface SpotifySession {\n accessToken: string;\n refreshToken: string;\n expirationDate: number;\n isExpired: boolean;\n}\n\nexport type SpotifyScope =\n | \"ugc-image-upload\"\n | \"user-read-playback-state\"\n | \"user-modify-playback-state\"\n | \"user-read-currently-playing\"\n | \"app-remote-control\"\n | \"streaming\"\n | \"playlist-read-private\"\n | \"playlist-read-collaborative\"\n | \"playlist-modify-private\"\n | \"playlist-modify-public\"\n | \"user-follow-modify\"\n | \"user-follow-read\"\n | \"user-top-read\"\n | \"user-read-recently-played\"\n | \"user-library-modify\"\n | \"user-library-read\"\n | \"user-read-email\"\n | \"user-read-private\";\n"]}
|
package/build/index.d.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
accessToken: string;
|
|
3
|
-
refreshToken: string;
|
|
4
|
-
expirationDate: number;
|
|
5
|
-
isExpired: boolean;
|
|
6
|
-
}
|
|
1
|
+
import { SpotifyScope, SpotifySession } from "./ExpoSpotifySDK.types";
|
|
7
2
|
declare function isAvailable(): boolean;
|
|
8
|
-
declare function authenticateAsync(scopes:
|
|
3
|
+
declare function authenticateAsync(scopes: SpotifyScope[]): Promise<SpotifySession>;
|
|
9
4
|
declare const Authenticate: {
|
|
10
5
|
authenticateAsync: typeof authenticateAsync;
|
|
11
6
|
};
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAGtE,iBAAS,WAAW,IAAI,OAAO,CAE9B;AAED,iBAAS,iBAAiB,CAAC,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,cAAc,CAAC,CAE1E;AAED,QAAA,MAAM,YAAY;;CAEjB,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,CAAC"}
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,oBAAoB,MAAM,wBAAwB,CAAC;AAE1D,SAAS,WAAW;IAClB,OAAO,oBAAoB,CAAC,WAAW,EAAE,CAAC;AAC5C,CAAC;AAED,SAAS,iBAAiB,CAAC,MAAsB;IAC/C,OAAO,oBAAoB,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,YAAY,GAAG;IACnB,iBAAiB;CAClB,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,CAAC","sourcesContent":["import { SpotifyScope, SpotifySession } from \"./ExpoSpotifySDK.types\";\nimport ExpoSpotifySDKModule from \"./ExpoSpotifySDKModule\";\n\nfunction isAvailable(): boolean {\n return ExpoSpotifySDKModule.isAvailable();\n}\n\nfunction authenticateAsync(scopes: SpotifyScope[]): Promise<SpotifySession> {\n return ExpoSpotifySDKModule.authenticate(scopes);\n}\n\nconst Authenticate = {\n authenticateAsync,\n};\n\nexport { isAvailable, Authenticate };\n"]}
|
|
@@ -3,9 +3,11 @@ import SpotifyiOS
|
|
|
3
3
|
|
|
4
4
|
public class ExpoSpotifyAuthDelegate: ExpoAppDelegateSubscriber {
|
|
5
5
|
let sessionManager = ExpoSpotifySessionManager.shared
|
|
6
|
-
|
|
6
|
+
|
|
7
7
|
public func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
|
|
8
|
-
sessionManager.sessionManager?.application(app, open: url, options: options)
|
|
9
|
-
|
|
8
|
+
if let canHandleURL = sessionManager.sessionManager?.application(app, open: url, options: options) {
|
|
9
|
+
return canHandleURL
|
|
10
|
+
}
|
|
11
|
+
return false
|
|
10
12
|
}
|
|
11
13
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wwdrew/expo-spotify-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Expo Module for native Spotify SDK",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -49,10 +49,5 @@
|
|
|
49
49
|
"expo": "*",
|
|
50
50
|
"react": "*",
|
|
51
51
|
"react-native": "*"
|
|
52
|
-
},
|
|
53
|
-
"dependencies": {
|
|
54
|
-
"axios": "^1.6.5",
|
|
55
|
-
"express": "^4.18.2",
|
|
56
|
-
"qs": "^6.11.2"
|
|
57
52
|
}
|
|
58
53
|
}
|
package/server.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
const axios = require("axios");
|
|
2
|
-
const crypto = require("crypto");
|
|
3
|
-
const express = require("express");
|
|
4
|
-
const qs = require("qs");
|
|
5
|
-
|
|
6
|
-
const app = express();
|
|
7
|
-
|
|
8
|
-
app.use(express.json());
|
|
9
|
-
app.use(express.urlencoded({ extended: true }));
|
|
10
|
-
app.use(express.json());
|
|
11
|
-
|
|
12
|
-
const CLIENT_ID = "<your_client_id>";
|
|
13
|
-
const CLIENT_SECRET = "<your_client_secret>";
|
|
14
|
-
const AUTH_HEADER =
|
|
15
|
-
"Basic " + Buffer.from(`${CLIENT_ID}:${CLIENT_SECRET}`).toString("base64"); // "CLIENT_ID + ":" + CLIENT_SECRET, "utf8").toString("base64");
|
|
16
|
-
|
|
17
|
-
const SPOTIFY_ACCOUNTS_ENDPOINT = "https://accounts.spotify.com";
|
|
18
|
-
const CLIENT_CALLBACK_URL = "expo-spotify-sdk-example://authenticate";
|
|
19
|
-
const ENCRYPTION_SECRET = "<your_encryption_secret>";
|
|
20
|
-
|
|
21
|
-
app.post("/swap", async (req, res) => {
|
|
22
|
-
console.log("WE'VE BEEN HIT!");
|
|
23
|
-
|
|
24
|
-
const auth_code = req.body.code;
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
const response = await axios.post(
|
|
28
|
-
`${SPOTIFY_ACCOUNTS_ENDPOINT}/api/token`,
|
|
29
|
-
qs.stringify({
|
|
30
|
-
grant_type: "authorization_code",
|
|
31
|
-
redirect_uri: CLIENT_CALLBACK_URL,
|
|
32
|
-
code: auth_code,
|
|
33
|
-
}),
|
|
34
|
-
{
|
|
35
|
-
headers: {
|
|
36
|
-
Authorization: AUTH_HEADER,
|
|
37
|
-
"Content-Type": "application/x-www-form-urlencoded",
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
if (response.status === 200) {
|
|
43
|
-
const token_data = response.data;
|
|
44
|
-
const refresh_token = token_data.refresh_token;
|
|
45
|
-
const cipher = crypto.createCipher("aes-256-cbc", ENCRYPTION_SECRET);
|
|
46
|
-
let encrypted_token = cipher.update(refresh_token, "utf8", "hex");
|
|
47
|
-
encrypted_token += cipher.final("hex");
|
|
48
|
-
token_data.refresh_token = encrypted_token;
|
|
49
|
-
|
|
50
|
-
console.log({ token_data });
|
|
51
|
-
|
|
52
|
-
res.status(response.status).json(token_data);
|
|
53
|
-
} else {
|
|
54
|
-
res.status(response.status).send(response.data);
|
|
55
|
-
}
|
|
56
|
-
} catch (error) {
|
|
57
|
-
res.status(500).send(error.message);
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
app.post("/refresh", async (req, res) => {
|
|
62
|
-
const encrypted_token = req.body.refresh_token;
|
|
63
|
-
const decipher = crypto.createDecipher("aes-256-cbc", ENCRYPTION_SECRET);
|
|
64
|
-
let refresh_token = decipher.update(encrypted_token, "hex", "utf8");
|
|
65
|
-
refresh_token += decipher.final("utf8");
|
|
66
|
-
|
|
67
|
-
try {
|
|
68
|
-
const response = await axios.post(
|
|
69
|
-
`${SPOTIFY_ACCOUNTS_ENDPOINT}/api/token`,
|
|
70
|
-
qs.stringify({
|
|
71
|
-
grant_type: "refresh_token",
|
|
72
|
-
refresh_token,
|
|
73
|
-
}),
|
|
74
|
-
{
|
|
75
|
-
headers: {
|
|
76
|
-
Authorization: AUTH_HEADER,
|
|
77
|
-
|
|
78
|
-
"Content-Type": "application/x-www-form-urlencoded",
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
console.log({ data: response.data });
|
|
84
|
-
|
|
85
|
-
res.status(response.status).send(response.data);
|
|
86
|
-
} catch (error) {
|
|
87
|
-
res.status(500).send(error.message);
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
app.listen(3000, () => {
|
|
92
|
-
console.log("Server is running on port 3000");
|
|
93
|
-
});
|