Last active
October 18, 2019 03:35
-
-
Save MrBuggySan/8d8b26a80ed0d34cf1b457d9cde73bf1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import UserInfo from './UserInfo'; | |
import Logout from './Logout'; | |
import Keycloak from 'keycloak-js'; | |
import queryString from "query-string"; | |
import axios from 'axios'; | |
class CallBackHey extends Component { | |
constructor(props) { | |
super(props); | |
this.redirect_uri = "http://localhost:3000" + this.props.location.pathname //the full uri of to get to this route | |
this.code = queryString.parse(this.props.location.search).code | |
} | |
componentDidMount() { | |
} | |
createNewResource(access_token) { | |
axios.defaults.headers.common = { | |
"Authorization": "Bearer " + access_token, | |
"Accept" : "application/json" | |
}; | |
// At this point, we should be able to access the endpoints of sirix-rest | |
axios.get('https://localhost:9443/hi').then(response => { | |
console.log(response) | |
}); | |
} | |
render() { | |
axios.post('https://localhost:9443/token', { | |
"code": this.code, | |
"redirect_uri": this.redirect_uri //extra meta data needed | |
}).then(response => { | |
var access_token = JSON.parse(response.request.response).access_token | |
this.createNewResource(access_token) | |
}) | |
return ( | |
<div>Got the access_token </div> | |
); | |
} | |
} | |
export default CallBackHey; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment