forked from supermamon/scriptable-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Save OAuth Client Info.js
50 lines (41 loc) · 1.4 KB
/
Save OAuth Client Info.js
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
50
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: purple; icon-glyph: save;
/*
Script : Save OAuth Client Info.js
Author : @supermamon
Version: 1.0.0
More Info: https://github.com/supermamon/oauth-proxy
*/
const FM = FileManager.iCloud();
const HOME = FM.documentsDirectory();
const jsonutil = importModule('./json-util.js')
const UI = importModule('./basic-ui.js')
async function askForText(caption, defaultValue) {
let prompt = new UI.Prompt(caption, defaultValue)
return await prompt.show()
}
async function alert(message) {
let msg = new Alert()
msg.message = message
await msg.present()
}
let app_name = await askForText('Application Name')
let client_id = await askForText('client_id')
let client_secret = await askForText('client_secret')
let redirect_uri = await askForText('redirect_uri')
let storage_dir = FM.joinPath(HOME, app_name)
if (!FM.fileExists(storage_dir)) {
FM.createDirectory(storage_dir)
}
let auth = `${client_id}:${client_secret}`
auth = Data.fromString(auth).toBase64String()
auth = `Basic ${auth}`
let client = {
client_id: client_id,
client_secret: client_secret,
authorization: auth,
redirect_uri: redirect_uri
}
jsonutil.writeToFile(client, FM.joinPath(storage_dir,'client.json'))
await alert(`Client Info saved to \n /Scriptable/${app_name}/client.json.`)