Guest User

Untitled

a guest
Nov 21st, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. export default class App extends Component {
  2. goGetToken() {
  3. return fetch('http://localhost:3000/oauth/token/?grant_type=password&username=pedroetb&password=password', {
  4. method: 'POST',
  5. headers: {
  6. 'Authorization': 'Basic YXBwbGljYXRpb246c2VjcmV0',
  7. 'Content-Type': 'application/application/x-www-form-urlencoded',
  8. },
  9. }).then(response => response.json())
  10. .then(responseJson => {
  11. console.log(responseJson.access_token);
  12. return responseJson.access_token;
  13. })
  14. .catch(error => {
  15. console.error(error);
  16. });
  17. }
  18.  
  19. componentDidMount() {
  20. this.goGetToken();
  21. }
  22. render() {
  23. return(
  24. <View></View>
  25. )
  26. }
  27. }
  28.  
  29. ### Obtaining a token
  30.  
  31. To obtain a token you should POST to `http://localhost:3000/oauth/token`.
  32.  
  33. #### With *password* grant
  34.  
  35. You need to include the client credentials in request headers and the user credentials and grant type in request body:
  36.  
  37. * **Headers**
  38. * **Authorization**: `"Basic " + clientId:secret base64'd`
  39. * (for example, to use `application:secret`, you should send `Basic YXBwbGljYXRpb246c2VjcmV0`)
  40.  
  41. * **Content-Type**: `application/x-www-form-urlencoded`
  42. * **Body**
  43. * `grant_type=password&username=pedroetb&password=password`
  44. * (contains 3 parameters: `grant_type`, `username` and `password`)
Add Comment
Please, Sign In to add comment