fix login
This commit is contained in:
parent
d9d50de3f6
commit
07a1d3b9c4
6 changed files with 34 additions and 35 deletions
|
|
@ -5,8 +5,9 @@ import { paramsString, promisedRequest } from './helpers.js'
|
|||
import { StatusCodeError } from 'src/services/errors/errors.js'
|
||||
|
||||
const REDIRECT_URI = `${window.location.origin}/oauth-callback`
|
||||
const MASTODON_APP_VERIFY_URL = '/api/v1/apps/verify_credentials'
|
||||
|
||||
export const createApp = ({ instance }) => {
|
||||
export const createApp = () => {
|
||||
const formData = new window.FormData()
|
||||
|
||||
formData.append('client_name', 'PleromaFE')
|
||||
|
|
@ -15,7 +16,7 @@ export const createApp = ({ instance }) => {
|
|||
formData.append('scopes', 'read write follow push admin')
|
||||
|
||||
return promisedRequest({
|
||||
url: `${instance}/api/v1/apps`,
|
||||
url: '/api/v1/apps',
|
||||
method: 'POST',
|
||||
formData,
|
||||
}).then(({ data, ...rest }) => ({
|
||||
|
|
@ -28,6 +29,12 @@ export const createApp = ({ instance }) => {
|
|||
}))
|
||||
}
|
||||
|
||||
export const verifyAppToken = ({ credentials }) =>
|
||||
promisedRequest({
|
||||
url: MASTODON_APP_VERIFY_URL,
|
||||
credentials,
|
||||
})
|
||||
|
||||
export const getLoginUrl = ({ instance, clientId }) => {
|
||||
const data = {
|
||||
responseType: 'code',
|
||||
|
|
@ -42,7 +49,6 @@ export const getLoginUrl = ({ instance, clientId }) => {
|
|||
export const getTokenWithCredentials = ({
|
||||
clientId,
|
||||
clientSecret,
|
||||
instance,
|
||||
username,
|
||||
password,
|
||||
}) => {
|
||||
|
|
@ -55,13 +61,13 @@ export const getTokenWithCredentials = ({
|
|||
formData.append('password', password)
|
||||
|
||||
return promisedRequest({
|
||||
url: `${instance}/oauth/token`,
|
||||
url: '/oauth/token',
|
||||
method: 'POST',
|
||||
formData,
|
||||
})
|
||||
}
|
||||
|
||||
export const getToken = ({ clientId, clientSecret, instance, code }) => {
|
||||
export const getToken = ({ clientId, clientSecret, code }) => {
|
||||
const formData = new window.FormData()
|
||||
|
||||
formData.append('client_id', clientId)
|
||||
|
|
@ -71,13 +77,13 @@ export const getToken = ({ clientId, clientSecret, instance, code }) => {
|
|||
formData.append('redirect_uri', `${window.location.origin}/oauth-callback`)
|
||||
|
||||
return promisedRequest({
|
||||
url: `${instance}/oauth/token`,
|
||||
url: '/oauth/token',
|
||||
method: 'POST',
|
||||
formData,
|
||||
})
|
||||
}
|
||||
|
||||
export const getClientToken = ({ clientId, clientSecret, instance }) => {
|
||||
export const getClientToken = ({ clientId, clientSecret }) => {
|
||||
const formData = new window.FormData()
|
||||
|
||||
formData.append('client_id', clientId)
|
||||
|
|
@ -86,13 +92,13 @@ export const getClientToken = ({ clientId, clientSecret, instance }) => {
|
|||
formData.append('redirect_uri', `${window.location.origin}/oauth-callback`)
|
||||
|
||||
return promisedRequest({
|
||||
url: `${instance}/oauth/token`,
|
||||
url: '/oauth/token',
|
||||
method: 'POST',
|
||||
formData,
|
||||
})
|
||||
}
|
||||
|
||||
export const verifyOTPCode = ({ app, instance, mfaToken, code }) => {
|
||||
export const verifyOTPCode = ({ app, mfaToken, code }) => {
|
||||
const formData = new window.FormData()
|
||||
|
||||
formData.append('client_id', app.client_id)
|
||||
|
|
@ -102,13 +108,13 @@ export const verifyOTPCode = ({ app, instance, mfaToken, code }) => {
|
|||
formData.append('challenge_type', 'totp')
|
||||
|
||||
return promisedRequest({
|
||||
url: `${instance}/oauth/mfa/challenge`,
|
||||
url: '/oauth/mfa/challenge',
|
||||
method: 'POST',
|
||||
formData,
|
||||
})
|
||||
}
|
||||
|
||||
export const verifyRecoveryCode = ({ app, instance, mfaToken, code }) => {
|
||||
export const verifyRecoveryCode = ({ app, mfaToken, code }) => {
|
||||
const formData = new window.FormData()
|
||||
|
||||
formData.append('client_id', app.client_id)
|
||||
|
|
@ -118,13 +124,13 @@ export const verifyRecoveryCode = ({ app, instance, mfaToken, code }) => {
|
|||
formData.append('challenge_type', 'recovery')
|
||||
|
||||
return promisedRequest({
|
||||
url: `${instance}/oauth/mfa/challenge`,
|
||||
url: '/oauth/mfa/challenge',
|
||||
method: 'POST',
|
||||
formData,
|
||||
})
|
||||
}
|
||||
|
||||
export const revokeToken = ({ app, instance, token }) => {
|
||||
export const revokeToken = ({ app, token }) => {
|
||||
const formData = new window.FormData()
|
||||
|
||||
formData.append('client_id', app.clientId)
|
||||
|
|
@ -132,7 +138,7 @@ export const revokeToken = ({ app, instance, token }) => {
|
|||
formData.append('token', token)
|
||||
|
||||
return promisedRequest({
|
||||
url: `${instance}/oauth/revoke`,
|
||||
url: '/oauth/revoke',
|
||||
method: 'POST',
|
||||
formData,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -54,7 +54,6 @@ const MASTODON_SEARCH_2 = '/api/v2/search'
|
|||
const MASTODON_USER_SEARCH_URL = '/api/v1/accounts/search'
|
||||
const MASTODON_STREAMING = '/api/v1/streaming'
|
||||
const MASTODON_KNOWN_DOMAIN_LIST_URL = '/api/v1/instance/peers'
|
||||
const MASTODON_ANNOUNCEMENTS_URL = '/api/v1/announcements'
|
||||
const PLEROMA_EMOJI_REACTIONS_URL = (id) =>
|
||||
`/api/v1/pleroma/statuses/${id}/reactions`
|
||||
const PLEROMA_SCROBBLES_URL = (id, { maxId, sinceId, minId, limit, offset }) =>
|
||||
|
|
@ -431,9 +430,6 @@ export const search2 = ({
|
|||
export const fetchKnownDomains = ({ credentials }) =>
|
||||
promisedRequest({ url: MASTODON_KNOWN_DOMAIN_LIST_URL, credentials })
|
||||
|
||||
export const getAnnouncements = ({ credentials }) =>
|
||||
promisedRequest({ url: MASTODON_ANNOUNCEMENTS_URL, credentials })
|
||||
|
||||
export const getMastodonSocketURI = (
|
||||
{ credentials, stream, args = {} },
|
||||
base,
|
||||
|
|
|
|||
|
|
@ -368,7 +368,6 @@ export const dismissAnnouncement = ({ id, credentials }) =>
|
|||
method: 'POST',
|
||||
})
|
||||
|
||||
|
||||
// #Imports
|
||||
export const importMutes = ({ file, credentials }) => {
|
||||
const formData = new FormData()
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import {
|
|||
windowWidth,
|
||||
} from '../services/window_utils/window_utils'
|
||||
|
||||
import { useAnnouncementsStore } from 'src/stores/announcements.js'
|
||||
import { useBookmarkFoldersStore } from 'src/stores/bookmark_folders.js'
|
||||
import { useEmojiStore } from 'src/stores/emoji.js'
|
||||
import { useInstanceStore } from 'src/stores/instance.js'
|
||||
|
|
@ -28,7 +29,6 @@ import { useMergedConfigStore } from 'src/stores/merged_config.js'
|
|||
import { useOAuthStore } from 'src/stores/oauth.js'
|
||||
import { useSyncConfigStore } from 'src/stores/sync_config.js'
|
||||
import { useUserHighlightStore } from 'src/stores/user_highlight.js'
|
||||
import { useAnnouncementsStore } from 'src/stores/announcements.js'
|
||||
|
||||
import { revokeToken } from 'src/api/oauth.js'
|
||||
import {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { defineStore } from 'pinia'
|
|||
|
||||
import { useOAuthStore } from 'src/stores/oauth.js'
|
||||
|
||||
import { getAnnouncements, dismissAnnouncement } from 'src/api/user.js'
|
||||
import { dismissAnnouncement, getAnnouncements } from 'src/api/user.js'
|
||||
|
||||
const FETCH_ANNOUNCEMENT_INTERVAL_MS = 1000 * 60 * 5
|
||||
|
||||
|
|
@ -83,18 +83,17 @@ export const useAnnouncementsStore = defineStore('announcements', {
|
|||
},
|
||||
markAnnouncementAsRead(id) {
|
||||
return dismissAnnouncement({
|
||||
id,
|
||||
credentials: useOAuthStore().token,
|
||||
})
|
||||
.then(() => {
|
||||
const index = this.announcements.findIndex((a) => a.id === id)
|
||||
id,
|
||||
credentials: useOAuthStore().token,
|
||||
}).then(() => {
|
||||
const index = this.announcements.findIndex((a) => a.id === id)
|
||||
|
||||
if (index < 0) {
|
||||
return
|
||||
}
|
||||
if (index < 0) {
|
||||
return
|
||||
}
|
||||
|
||||
this.announcements[index].read = true
|
||||
})
|
||||
this.announcements[index].read = true
|
||||
})
|
||||
},
|
||||
startFetchingAnnouncements() {
|
||||
if (this.fetchAnnouncementsTimer) {
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@ import { defineStore } from 'pinia'
|
|||
|
||||
import { useInstanceStore } from 'src/stores/instance.js'
|
||||
|
||||
import { createApp, getClientToken } from 'src/api/oauth.js'
|
||||
import { verifyCredentials } from 'src/api/public.js'
|
||||
import { createApp, getClientToken, verifyAppToken } from 'src/api/oauth.js'
|
||||
|
||||
// status codes about verifyAppToken (GET /api/v1/apps/verify_credentials)
|
||||
const isAppTokenRejected = (error) =>
|
||||
|
|
@ -39,7 +38,7 @@ export const useOAuthStore = defineStore('oauth', {
|
|||
}),
|
||||
getters: {
|
||||
token() {
|
||||
return this.userToken || this.appToken
|
||||
return this.userToken
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
|
|
@ -90,7 +89,7 @@ export const useOAuthStore = defineStore('oauth', {
|
|||
async ensureAppToken() {
|
||||
if (this.appToken) {
|
||||
try {
|
||||
await verifyCredentials({
|
||||
await verifyAppToken({
|
||||
credentials: this.appToken,
|
||||
})
|
||||
return this.appToken
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue