Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export default class App extends Component {
- goGetToken() {
- return fetch('http://localhost:3000/oauth/token/?grant_type=password&username=pedroetb&password=password', {
- method: 'POST',
- headers: {
- 'Authorization': 'Basic YXBwbGljYXRpb246c2VjcmV0',
- 'Content-Type': 'application/application/x-www-form-urlencoded',
- },
- }).then(response => response.json())
- .then(responseJson => {
- console.log(responseJson.access_token);
- return responseJson.access_token;
- })
- .catch(error => {
- console.error(error);
- });
- }
- componentDidMount() {
- this.goGetToken();
- }
- render() {
- return(
- <View></View>
- )
- }
- }
- ### Obtaining a token
- To obtain a token you should POST to `http://localhost:3000/oauth/token`.
- #### With *password* grant
- You need to include the client credentials in request headers and the user credentials and grant type in request body:
- * **Headers**
- * **Authorization**: `"Basic " + clientId:secret base64'd`
- * (for example, to use `application:secret`, you should send `Basic YXBwbGljYXRpb246c2VjcmV0`)
- * **Content-Type**: `application/x-www-form-urlencoded`
- * **Body**
- * `grant_type=password&username=pedroetb&password=password`
- * (contains 3 parameters: `grant_type`, `username` and `password`)
Add Comment
Please, Sign In to add comment