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 {
|
export default class Auth extends Vue {
|
||||||
public instance: Instance = ""
|
public instance: Instance = ""
|
||||||
public inputCode: boolean = false
|
public inputCode: boolean = false
|
||||||
|
public code: string
|
||||||
public get hasDomain() {
|
public get hasDomain() {
|
||||||
return this.instance != ""
|
return this.instance != ""
|
||||||
}
|
}
|
||||||
|
@ -37,7 +38,7 @@ export default class Auth extends Vue {
|
||||||
public authCode() {
|
public authCode() {
|
||||||
let code = this.code
|
let code = this.code
|
||||||
this.inputCode = true
|
this.inputCode = true
|
||||||
ipcRenderer.send(`new-account-setup`, target)
|
ipcRenderer.send(`new-account-auth`, code, this.instance)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -3,36 +3,42 @@ import Mastodon from "megalodon"
|
||||||
|
|
||||||
export default class Auth {
|
export default class Auth {
|
||||||
public static ready() {
|
public static ready() {
|
||||||
|
let clientId: string
|
||||||
|
let clientSecret: string
|
||||||
ipcMain.on("new-account-setup", async (event: Event, instance: string) => {
|
ipcMain.on("new-account-setup", async (event: Event, instance: string) => {
|
||||||
const SCOPES: string = "read write follow"
|
const SCOPES: string = "read write follow"
|
||||||
let clientId: string
|
|
||||||
let clientSecret: string
|
|
||||||
let url: string | null
|
let url: string | null
|
||||||
Mastodon.registerApp(
|
Mastodon.registerApp(
|
||||||
"TheDesk",
|
"TheDesk",
|
||||||
{
|
{
|
||||||
scopes: SCOPES
|
scopes: SCOPES
|
||||||
},
|
},
|
||||||
"https://"+instance
|
"https://" + instance
|
||||||
).then(appData => {
|
).then(appData => {
|
||||||
clientId = appData.clientId
|
clientId = appData.clientId
|
||||||
clientSecret = appData.clientSecret
|
clientSecret = appData.clientSecret
|
||||||
url = appData.url
|
url = appData.url
|
||||||
if(url){
|
if (url) {
|
||||||
shell.openExternal(
|
shell.openExternal(
|
||||||
url,
|
url,
|
||||||
{
|
{
|
||||||
activate: false
|
activate: false
|
||||||
},
|
},
|
||||||
err => {
|
err => {
|
||||||
if (err) console.log(err)
|
if (err) console.log(err)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}else{
|
} else {
|
||||||
console.log(appData)
|
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