Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. export async function authorizeClient(urbitAddress, urbitCode) {
  2.   return new Promise(async (resolve, reject) => {
  3.     try {
  4.       const headers = { "Content-Type": "application/x-www-form-urlencoded" }
  5.       const res = await http.request({
  6.         url: `${urbitAddress}/~/login`,
  7.         method: 'POST',
  8.         content: `password=${urbitCode}`,
  9.         headers,
  10.       })
  11.  
  12.       if(res.statusCode === 200) {
  13.         const cookieHeader = res.headers['set-cookie']
  14.         resolve(cookieHeader.split(';')[0])
  15.       } else {
  16.         reject('Authorization failed.')
  17.       }
  18.     } catch (ex) {
  19.       console.log(ex.stack)
  20.       reject(ex)
  21.     }
  22.   })
  23. }
  24.  
  25. export async function verifyServer(urbitAddress) {
  26.   return new Promise(async (resolve) => {
  27.     try {
  28.       const res = await http.request({
  29.         url: `${urbitAddress}/~/login`,
  30.         method: 'GET',
  31.       })
  32.  
  33.       if(res.statusCode === 200) {
  34.         resolve(true)
  35.       } else {
  36.         resolve(false)
  37.       }
  38.     } catch (ex) {
  39.       console.log(ex.stack)
  40.       resolve(false)
  41.     }
  42.   })
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement