SHARE
TWEET

Untitled

a guest Oct 4th, 2017 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fetch('http://blt.dev/session/token')  
  2.   .then(  
  3.     function(response) {  
  4.       if (response.status !== 200) {  
  5.         console.log('Looks like there was a problem. Status Code: ' +  
  6.           response.status);  
  7.         return;  
  8.       }
  9.  
  10.       // Examine the text in the response  
  11.       response.text().then(function(data) {  
  12.         console.log(data);  
  13.       });  
  14.     }  
  15.   )  
  16.   .catch(function(err) {  
  17.     console.log('Fetch Error :-S', err);  
  18.   });
  19.    
  20. fetch('http://blt.dev/api/v1/token?_format=hal_json', {
  21.      method: 'POST',
  22.      credentials: 'include',
  23.      headers: {
  24.        'Content-Type': 'application/hal+json',
  25.        'X-CSRF-Token': 'GVRpRLO_GkJbPRd00JEfvXP7ycSIP4UYR766zuGchRc',
  26.        'Authorization': 'json_auth'
  27.      },
  28.      body: JSON.stringify({ username: 'admin', password: 'admin' })
  29.    })
  30.    .then(function(response){
  31.       if(!response.ok){
  32.         throw Error(response.statusText);
  33.       }
  34.       return response;
  35.    })
  36.    .then(function(response){
  37.       return response.json()
  38.    })
  39.    .then(response => {
  40.      try {
  41.       console.log(response.token)
  42.        return response.token;
  43.      } catch (e) {
  44.        console.log(e);
  45.      }
  46.    })
  47.    .catch(error => {
  48.      console.log(error);
  49.    });
  50.    
  51. Error: Forbidden
  52.     at <anonymous>:13:15
  53.     at <anonymous>
  54.    
  55. eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpYXQiOjE1MDcxMTk5MjYsImV4cCI6MTUwNzEyMzUyNiwiZHJ1cGFsIjp7InVpZCI6IjEifX0.MS9FvAIseMeD0rZr7-h_b74Sj7BoGi7rCd9wNDa0ypOlvFBNI5sWOs6NWUOlHe_sI7eQMkFfaovgoUIShf9-N3rnZKhQm8fKGxTzqi_s1dCxkIm62vf-2a6NaX0i0t-PtWaMkhd7BUdA4E__N9BzXexnHz3kroicjqQJ0hH17ub0sSOTtNjnWtMjjX35LH0vY17eLaCsOmXpYQzEiUDaAthVJaR3azwwQTc8ChVXbtLYgPWtbekObi-hsliZBdDmz41HnqgIrhjlrnrkWQzlxoOsB_UiD4Ht9oy4GJfzKKi5wbGZ6ayGv7XPoIuih1uJFgAquRmgFeHlbXhH2mhbyQ
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top