@wwdrew/expo-spotify-sdk 0.1.0 → 0.2.0
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 +12 -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 +5 -2
- package/build/index.js.map +1 -1
- package/ios/ExpoSpotifyAuthDelegate.swift +5 -3
- package/ios/ExpoSpotifyConfiguration.swift +4 -9
- package/ios/ExpoSpotifySDKModule.swift +10 -3
- package/ios/ExpoSpotifySessionManager.swift +29 -27
- package/package.json +1 -6
- package/plugin/build/index.js +10 -7
- package/plugin/build/types.d.ts +0 -2
- package/server.js +0 -93
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export interface SpotifySession {
|
|
2
|
+
accessToken: string;
|
|
3
|
+
refreshToken: string;
|
|
4
|
+
expirationDate: number;
|
|
5
|
+
isExpired: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface SpotifyConfig {
|
|
8
|
+
scopes: SpotifyScope[];
|
|
9
|
+
tokenSwapURL?: string;
|
|
10
|
+
tokenRefreshURL?: string;
|
|
11
|
+
}
|
|
12
|
+
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
13
|
//# 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,WAAW,aAAa;IAC5B,MAAM,EAAE,YAAY,EAAE,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;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 interface SpotifyConfig {\n scopes: SpotifyScope[];\n tokenSwapURL?: string;\n tokenRefreshURL?: string;\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 { SpotifyConfig, SpotifySession } from "./ExpoSpotifySDK.types";
|
|
7
2
|
declare function isAvailable(): boolean;
|
|
8
|
-
declare function authenticateAsync(
|
|
3
|
+
declare function authenticateAsync(config: SpotifyConfig): 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,aAAa,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAGvE,iBAAS,WAAW,IAAI,OAAO,CAE9B;AAED,iBAAS,iBAAiB,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC,CAMzE;AAED,QAAA,MAAM,YAAY;;CAEjB,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,CAAC"}
|
package/build/index.js
CHANGED
|
@@ -2,8 +2,11 @@ import ExpoSpotifySDKModule from "./ExpoSpotifySDKModule";
|
|
|
2
2
|
function isAvailable() {
|
|
3
3
|
return ExpoSpotifySDKModule.isAvailable();
|
|
4
4
|
}
|
|
5
|
-
function authenticateAsync(
|
|
6
|
-
|
|
5
|
+
function authenticateAsync(config) {
|
|
6
|
+
if (!config.scopes || config.scopes?.length === 0) {
|
|
7
|
+
throw new Error("scopes are required");
|
|
8
|
+
}
|
|
9
|
+
return ExpoSpotifySDKModule.authenticateAsync(config);
|
|
7
10
|
}
|
|
8
11
|
const Authenticate = {
|
|
9
12
|
authenticateAsync,
|
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,MAAqB;IAC9C,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,KAAK,CAAC,EAAE,CAAC;QAClD,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;IACzC,CAAC;IAED,OAAO,oBAAoB,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;AACxD,CAAC;AAED,MAAM,YAAY,GAAG;IACnB,iBAAiB;CAClB,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,CAAC","sourcesContent":["import { SpotifyConfig, SpotifySession } from \"./ExpoSpotifySDK.types\";\nimport ExpoSpotifySDKModule from \"./ExpoSpotifySDKModule\";\n\nfunction isAvailable(): boolean {\n return ExpoSpotifySDKModule.isAvailable();\n}\n\nfunction authenticateAsync(config: SpotifyConfig): Promise<SpotifySession> {\n if (!config.scopes || config.scopes?.length === 0) {\n throw new Error(\"scopes are required\");\n }\n\n return ExpoSpotifySDKModule.authenticateAsync(config);\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
|
}
|
|
@@ -4,22 +4,17 @@ struct ExpoSpotifyConfiguration: Codable {
|
|
|
4
4
|
let clientID: String
|
|
5
5
|
let host: String
|
|
6
6
|
let scheme: String
|
|
7
|
-
|
|
8
|
-
let tokenSwapURL: URL?
|
|
9
|
-
|
|
7
|
+
|
|
10
8
|
var redirectURL: URL? {
|
|
11
9
|
return URL(string: "\(scheme)://\(host)")
|
|
12
10
|
}
|
|
13
|
-
|
|
11
|
+
|
|
14
12
|
init(clientID: String = "defaultClientID",
|
|
15
13
|
host: String = "defaultHost",
|
|
16
|
-
scheme: String = "defaultScheme"
|
|
17
|
-
|
|
18
|
-
tokenSwapURL: URL? = nil) {
|
|
14
|
+
scheme: String = "defaultScheme"
|
|
15
|
+
) {
|
|
19
16
|
self.clientID = clientID
|
|
20
17
|
self.host = host
|
|
21
18
|
self.scheme = scheme
|
|
22
|
-
self.tokenRefreshURL = tokenRefreshURL
|
|
23
|
-
self.tokenSwapURL = tokenSwapURL
|
|
24
19
|
}
|
|
25
20
|
}
|
|
@@ -3,7 +3,6 @@ import SpotifyiOS
|
|
|
3
3
|
|
|
4
4
|
public class ExpoSpotifySDKModule: Module {
|
|
5
5
|
|
|
6
|
-
|
|
7
6
|
public func definition() -> ModuleDefinition {
|
|
8
7
|
|
|
9
8
|
let spotifySession = ExpoSpotifySessionManager.shared
|
|
@@ -14,8 +13,16 @@ public class ExpoSpotifySDKModule: Module {
|
|
|
14
13
|
return spotifySession.spotifyAppInstalled()
|
|
15
14
|
}
|
|
16
15
|
|
|
17
|
-
AsyncFunction("
|
|
18
|
-
|
|
16
|
+
AsyncFunction("authenticateAsync") { (config: [String: Any], promise: Promise) in
|
|
17
|
+
guard let scopes = config["scopes"] as? [String] else {
|
|
18
|
+
promise.reject("INVALID_CONFIG", "Invalid SpotifyConfig object")
|
|
19
|
+
return
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let tokenSwapURL = config["tokenSwapURL"] as? String
|
|
23
|
+
let tokenRefreshURL = config["tokenRefreshURL"] as? String
|
|
24
|
+
|
|
25
|
+
spotifySession.authenticate(scopes: scopes, tokenSwapURL: tokenSwapURL, tokenRefreshURL: tokenRefreshURL).done { session in
|
|
19
26
|
let sessionData: [String: Any] = [
|
|
20
27
|
"accessToken": session.accessToken,
|
|
21
28
|
"refreshToken": session.refreshToken,
|
|
@@ -4,14 +4,15 @@ import PromiseKit
|
|
|
4
4
|
|
|
5
5
|
enum SessionManagerError: Error {
|
|
6
6
|
case notInitialized
|
|
7
|
+
case invalidConfiguration
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
final class ExpoSpotifySessionManager: NSObject {
|
|
10
11
|
weak var module: ExpoSpotifySDKModule?
|
|
11
12
|
var authPromiseSeal: Resolver<SPTSession>?
|
|
12
|
-
|
|
13
|
+
|
|
13
14
|
static let shared = ExpoSpotifySessionManager()
|
|
14
|
-
|
|
15
|
+
|
|
15
16
|
private var expoSpotifyConfiguration: ExpoSpotifyConfiguration? {
|
|
16
17
|
guard let expoSpotifySdkDict = Bundle.main.object(forInfoDictionaryKey: "ExpoSpotifySDK") as? [String: String],
|
|
17
18
|
let clientID = expoSpotifySdkDict["clientID"],
|
|
@@ -20,63 +21,64 @@ final class ExpoSpotifySessionManager: NSObject {
|
|
|
20
21
|
{
|
|
21
22
|
return nil
|
|
22
23
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
let tokenSwapURL = URL(string: expoSpotifySdkDict["tokenSwapURL"] ?? "")
|
|
26
|
-
|
|
27
|
-
return ExpoSpotifyConfiguration(clientID: clientID, host: host, scheme: scheme, tokenRefreshURL: tokenRefreshURL, tokenSwapURL: tokenSwapURL)
|
|
24
|
+
|
|
25
|
+
return ExpoSpotifyConfiguration(clientID: clientID, host: host, scheme: scheme)
|
|
28
26
|
}
|
|
29
|
-
|
|
27
|
+
|
|
30
28
|
lazy var configuration: SPTConfiguration? = {
|
|
31
29
|
guard let clientID = expoSpotifyConfiguration?.clientID,
|
|
32
30
|
let redirectURL = expoSpotifyConfiguration?.redirectURL else {
|
|
33
31
|
NSLog("Invalid Spotify configuration")
|
|
34
32
|
return nil
|
|
35
33
|
}
|
|
36
|
-
|
|
34
|
+
|
|
37
35
|
return SPTConfiguration(clientID: clientID, redirectURL: redirectURL)
|
|
38
36
|
}()
|
|
39
|
-
|
|
37
|
+
|
|
40
38
|
lazy var sessionManager: SPTSessionManager? = {
|
|
41
39
|
guard let configuration = configuration else {
|
|
42
40
|
return nil
|
|
43
41
|
}
|
|
44
|
-
|
|
45
|
-
configuration.tokenSwapURL = expoSpotifyConfiguration?.tokenSwapURL
|
|
46
|
-
configuration.tokenRefreshURL = expoSpotifyConfiguration?.tokenRefreshURL
|
|
47
|
-
|
|
42
|
+
|
|
48
43
|
return SPTSessionManager(configuration: configuration, delegate: self)
|
|
49
44
|
}()
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
func authenticate(
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
func authenticate(scopes: [String], tokenSwapURL: String?, tokenRefreshURL: String?) -> PromiseKit.Promise<SPTSession> {
|
|
53
48
|
return Promise { seal in
|
|
54
|
-
guard let
|
|
55
|
-
|
|
56
|
-
|
|
49
|
+
guard let clientID = expoSpotifyConfiguration?.clientID,
|
|
50
|
+
let redirectURL = expoSpotifyConfiguration?.redirectURL else {
|
|
51
|
+
NSLog("Invalid Spotify configuration")
|
|
52
|
+
seal.reject(SessionManagerError.invalidConfiguration)
|
|
57
53
|
return
|
|
58
54
|
}
|
|
55
|
+
let configuration = SPTConfiguration(clientID: clientID, redirectURL: redirectURL)
|
|
59
56
|
|
|
57
|
+
configuration.tokenSwapURL = URL(string: tokenSwapURL ?? "")
|
|
58
|
+
configuration.tokenRefreshURL = URL(string: tokenRefreshURL ?? "")
|
|
59
|
+
|
|
60
|
+
self.sessionManager = SPTSessionManager(configuration: configuration, delegate: self)
|
|
61
|
+
|
|
60
62
|
self.authPromiseSeal = seal
|
|
61
|
-
|
|
63
|
+
|
|
62
64
|
DispatchQueue.main.sync {
|
|
63
|
-
sessionManager
|
|
65
|
+
sessionManager?.initiateSession(with: SPTScopeSerializer.deserializeScopes(scopes), options: .default)
|
|
64
66
|
}
|
|
65
67
|
}
|
|
66
68
|
}
|
|
67
|
-
|
|
69
|
+
|
|
68
70
|
func spotifyAppInstalled() -> Bool {
|
|
69
71
|
guard let sessionManager = sessionManager else {
|
|
70
|
-
NSLog("
|
|
72
|
+
NSLog("SPTSessionManager not initialized")
|
|
71
73
|
return false
|
|
72
74
|
}
|
|
73
|
-
|
|
75
|
+
|
|
74
76
|
var isInstalled = false
|
|
75
|
-
|
|
77
|
+
|
|
76
78
|
DispatchQueue.main.sync {
|
|
77
79
|
isInstalled = sessionManager.isSpotifyAppInstalled
|
|
78
80
|
}
|
|
79
|
-
|
|
81
|
+
|
|
80
82
|
return isInstalled
|
|
81
83
|
}
|
|
82
84
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wwdrew/expo-spotify-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
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/plugin/build/index.js
CHANGED
|
@@ -5,13 +5,16 @@ const withSpotifyAndroidAppBuildGradle_1 = require("./android/withSpotifyAndroid
|
|
|
5
5
|
const withSpotifyQueryScheme_1 = require("./ios/withSpotifyQueryScheme");
|
|
6
6
|
const withSpotifyURLScheme_1 = require("./ios/withSpotifyURLScheme");
|
|
7
7
|
const withSpotifyConfig_1 = require("./withSpotifyConfig");
|
|
8
|
-
const withSpotifySdkConfig = (config, spotifyConfig
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
8
|
+
const withSpotifySdkConfig = (config, spotifyConfig) => {
|
|
9
|
+
if (!spotifyConfig.host) {
|
|
10
|
+
throw new Error("Missing required Spotify config value: host");
|
|
11
|
+
}
|
|
12
|
+
if (!spotifyConfig.scheme) {
|
|
13
|
+
throw new Error("Missing required Spotify config value: scheme");
|
|
14
|
+
}
|
|
15
|
+
if (!spotifyConfig.clientID) {
|
|
16
|
+
throw new Error("Missing required Spotify config value: clientID");
|
|
17
|
+
}
|
|
15
18
|
config = (0, withSpotifyConfig_1.withSpotifyConfig)(config, spotifyConfig);
|
|
16
19
|
// Android specific
|
|
17
20
|
config = (0, withSpotifyAndroidAppBuildGradle_1.withSpotifyAndroidAppBuildGradle)(config, spotifyConfig);
|
package/plugin/build/types.d.ts
CHANGED
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
|
-
});
|