-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathspotify-auth.js
More file actions
50 lines (39 loc) · 1.29 KB
/
spotify-auth.js
File metadata and controls
50 lines (39 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: deep-green; icon-glyph: rss-square;
/*
Script : spotify-auth.js
Author : @supermamon
Version: 1.0.0
More Info: https://github.com/supermamon/oauth-proxy
Assumptions:
* a `spotify` directory under the Scriptable
that contains `client.json`. Use the
`Save OAuth Client Info` script to generate
`client.json
*/
const FM = FileManager.iCloud();
const HOME = FM.documentsDirectory();
const Spotify = importModule('./spotify-api.js')
// new instance of the Spotify client
const app = new Spotify(FM.joinPath(HOME, 'spotify'))
async function alert(message) {
let msg = new Alert()
msg.message = message
await msg.present()
}
// if not `code` argument is passed, start the
// authentiation
if (!args.queryParameters['code']) {
let scope = 'user-read-recently-played'
let state = 'sriptable-for-iphone'
app.launchAuthentication(scope, state)
} else {
// else get the access token
let token = await app.getAccessToken({
code: args.queryParameters['code'],
state: args.queryParameters['state']
})
await app.getUser()
await alert(`${app.user.display_name} authenticated. Access expires on ${app.token.expires_on.toString()}.`)
}