Add: get access token
This commit is contained in:
parent
4887dfbd5b
commit
fd719a0235
|
@ -26,6 +26,7 @@ type Instance = string
|
|||
export default class Auth extends Vue {
|
||||
public instance: Instance = ""
|
||||
public inputCode: boolean = false
|
||||
public code: string
|
||||
public get hasDomain() {
|
||||
return this.instance != ""
|
||||
}
|
||||
|
@ -37,7 +38,7 @@ export default class Auth extends Vue {
|
|||
public authCode() {
|
||||
let code = this.code
|
||||
this.inputCode = true
|
||||
ipcRenderer.send(`new-account-setup`, target)
|
||||
ipcRenderer.send(`new-account-auth`, code, this.instance)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -3,36 +3,42 @@ import Mastodon from "megalodon"
|
|||
|
||||
export default class Auth {
|
||||
public static ready() {
|
||||
let clientId: string
|
||||
let clientSecret: string
|
||||
ipcMain.on("new-account-setup", async (event: Event, instance: string) => {
|
||||
const SCOPES: string = "read write follow"
|
||||
let clientId: string
|
||||
let clientSecret: string
|
||||
let url: string | null
|
||||
Mastodon.registerApp(
|
||||
"TheDesk",
|
||||
{
|
||||
scopes: SCOPES
|
||||
},
|
||||
"https://"+instance
|
||||
"https://" + instance
|
||||
).then(appData => {
|
||||
clientId = appData.clientId
|
||||
clientSecret = appData.clientSecret
|
||||
url = appData.url
|
||||
if(url){
|
||||
shell.openExternal(
|
||||
url,
|
||||
{
|
||||
activate: false
|
||||
},
|
||||
err => {
|
||||
if (err) console.log(err)
|
||||
}
|
||||
)
|
||||
}else{
|
||||
console.log(appData)
|
||||
if (url) {
|
||||
shell.openExternal(
|
||||
url,
|
||||
{
|
||||
activate: false
|
||||
},
|
||||
err => {
|
||||
if (err) console.log(err)
|
||||
}
|
||||
)
|
||||
} else {
|
||||
console.log(appData)
|
||||
}
|
||||
|
||||
})
|
||||
})
|
||||
ipcMain.on("new-account-auth", async (event: Event, code: string, instance: string) => {
|
||||
Mastodon.fetchAccessToken(clientId, clientSecret, code, "https://"+instance)
|
||||
.then((tokenData: Partial<{ accessToken: string }>) => {
|
||||
console.log(tokenData.accessToken)
|
||||
})
|
||||
.catch((err: Error) => console.error(err))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user