chore: wip oauth
This commit is contained in:
parent
6755ed6f94
commit
6ea4879190
8 changed files with 75 additions and 10 deletions
|
@ -1,6 +1,7 @@
|
|||
<script setup lang="ts">
|
||||
const token = useCookie('nuxtodon-token')
|
||||
const router = useRouter()
|
||||
// TODO: move to middleware
|
||||
if (!token.value)
|
||||
router.replace('/public')
|
||||
|
||||
|
|
|
@ -1,10 +1,41 @@
|
|||
<script setup lang="ts">
|
||||
import { login } from 'masto'
|
||||
import { DEFAULT_SERVER } from '~/plugins/masto'
|
||||
|
||||
const server = useCookie('nuxtodon-server')
|
||||
const token = useCookie('nuxtodon-token')
|
||||
|
||||
async function oauth() {
|
||||
const client = await login({
|
||||
url: `https://${server.value || DEFAULT_SERVER}`,
|
||||
})
|
||||
const redirectUri = `${location.origin}/api/${server.value || DEFAULT_SERVER}/oauth`
|
||||
const app = await client.apps.create({
|
||||
clientName: 'Nuxtodon',
|
||||
redirectUris: redirectUri,
|
||||
scopes: 'read write follow push',
|
||||
})
|
||||
|
||||
console.log({ app })
|
||||
|
||||
const url = `https://${server.value || DEFAULT_SERVER}/oauth/authorize
|
||||
?client_id=${app.clientId}
|
||||
&scope=read+write+follow+push
|
||||
&redirect_uri=${encodeURIComponent(redirectUri)}
|
||||
&response_type=code`.replace(/\n/g, '')
|
||||
|
||||
const a = document.createElement('a')
|
||||
a.href = url
|
||||
a.target = '_blank'
|
||||
a.click()
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div p4>
|
||||
<button @click="oauth()">
|
||||
OAuth
|
||||
</button>
|
||||
<input
|
||||
v-model="server"
|
||||
placeholder="Server URL"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue