aboutsummaryrefslogtreecommitdiff
path: root/src/services/new_api
diff options
context:
space:
mode:
authorHenry Jameson <me@hjkos.com>2019-08-31 22:38:02 +0300
committerHenry Jameson <me@hjkos.com>2019-08-31 22:38:02 +0300
commit18ec13d796c0928d09fa93de4117822d2e35502c (patch)
tree1cfb4d68a246c604396bb64bbba3e69bdf4fe511 /src/services/new_api
parentb3e9a5a71819c7d3a4b35c5b6ad551785a7ba44f (diff)
parent018a650166a5dce0878b696359a999ab67634cfc (diff)
Merge remote-tracking branch 'upstream/develop' into docs
* upstream/develop: (193 commits) fix user avatar fallback logic remove dead code make bio textarea resizable vertically only remove dead code remove dead code fix crazy watch logic in conversation show three dot button only if needed hide mute conversation button to guests update keyBy generate idObj at timeline level fix pin showing logic in conversation Show a message when JS is disabled Initialize chat only if user is logged in and it wasn't initialized before i18n/Update Japanese i18n/Update pedantic Japanese sync profile tab state with location query refactor TabSwitcher use better name of controlled prop fix potential bug to render active tab in controlled way remove unused param ...
Diffstat (limited to 'src/services/new_api')
-rw-r--r--src/services/new_api/mfa.js4
-rw-r--r--src/services/new_api/oauth.js21
-rw-r--r--src/services/new_api/user_search.js19
-rw-r--r--src/services/new_api/utils.js36
4 files changed, 20 insertions, 60 deletions
diff --git a/src/services/new_api/mfa.js b/src/services/new_api/mfa.js
index ddf90e6b..cbba06d5 100644
--- a/src/services/new_api/mfa.js
+++ b/src/services/new_api/mfa.js
@@ -1,4 +1,4 @@
-const verifyOTPCode = ({app, instance, mfaToken, code}) => {
+const verifyOTPCode = ({ app, instance, mfaToken, code }) => {
const url = `${instance}/oauth/mfa/challenge`
const form = new window.FormData()
@@ -14,7 +14,7 @@ const verifyOTPCode = ({app, instance, mfaToken, code}) => {
}).then((data) => data.json())
}
-const verifyRecoveryCode = ({app, instance, mfaToken, code}) => {
+const verifyRecoveryCode = ({ app, instance, mfaToken, code }) => {
const url = `${instance}/oauth/mfa/challenge`
const form = new window.FormData()
diff --git a/src/services/new_api/oauth.js b/src/services/new_api/oauth.js
index 030e9980..d0d18c03 100644
--- a/src/services/new_api/oauth.js
+++ b/src/services/new_api/oauth.js
@@ -93,7 +93,7 @@ export const getClientToken = ({ clientId, clientSecret, instance }) => {
body: form
}).then((data) => data.json())
}
-const verifyOTPCode = ({app, instance, mfaToken, code}) => {
+const verifyOTPCode = ({ app, instance, mfaToken, code }) => {
const url = `${instance}/oauth/mfa/challenge`
const form = new window.FormData()
@@ -109,7 +109,7 @@ const verifyOTPCode = ({app, instance, mfaToken, code}) => {
}).then((data) => data.json())
}
-const verifyRecoveryCode = ({app, instance, mfaToken, code}) => {
+const verifyRecoveryCode = ({ app, instance, mfaToken, code }) => {
const url = `${instance}/oauth/mfa/challenge`
const form = new window.FormData()
@@ -125,13 +125,28 @@ const verifyRecoveryCode = ({app, instance, mfaToken, code}) => {
}).then((data) => data.json())
}
+const revokeToken = ({ app, instance, token }) => {
+ const url = `${instance}/oauth/revoke`
+ const form = new window.FormData()
+
+ form.append('client_id', app.clientId)
+ form.append('client_secret', app.clientSecret)
+ form.append('token', token)
+
+ return window.fetch(url, {
+ method: 'POST',
+ body: form
+ }).then((data) => data.json())
+}
+
const oauth = {
login,
getToken,
getTokenWithCredentials,
getOrCreateApp,
verifyOTPCode,
- verifyRecoveryCode
+ verifyRecoveryCode,
+ revokeToken
}
export default oauth
diff --git a/src/services/new_api/user_search.js b/src/services/new_api/user_search.js
deleted file mode 100644
index 869afa9c..00000000
--- a/src/services/new_api/user_search.js
+++ /dev/null
@@ -1,19 +0,0 @@
-import utils from './utils.js'
-import { parseUser } from '../entity_normalizer/entity_normalizer.service.js'
-
-const search = ({query, store}) => {
- return utils.request({
- store,
- url: '/api/v1/accounts/search',
- params: {
- q: query
- }
- })
- .then((data) => data.json())
- .then((data) => data.map(parseUser))
-}
-const UserSearch = {
- search
-}
-
-export default UserSearch
diff --git a/src/services/new_api/utils.js b/src/services/new_api/utils.js
deleted file mode 100644
index 6696573b..00000000
--- a/src/services/new_api/utils.js
+++ /dev/null
@@ -1,36 +0,0 @@
-const queryParams = (params) => {
- return Object.keys(params)
- .map(k => encodeURIComponent(k) + '=' + encodeURIComponent(params[k]))
- .join('&')
-}
-
-const headers = (store) => {
- const accessToken = store.getters.getToken()
- if (accessToken) {
- return { 'Authorization': `Bearer ${accessToken}` }
- } else {
- return {}
- }
-}
-
-const request = ({method = 'GET', url, params, store}) => {
- const instance = store.state.instance.server
- let fullUrl = `${instance}${url}`
-
- if (method === 'GET' && params) {
- fullUrl = fullUrl + `?${queryParams(params)}`
- }
-
- return window.fetch(fullUrl, {
- method,
- headers: headers(store),
- credentials: 'same-origin'
- })
-}
-
-const utils = {
- queryParams,
- request
-}
-
-export default utils