Home > Blockchain >  how to Use the client ID and client secret to obtain an access token using the OAuth 2.0 protocol
how to Use the client ID and client secret to obtain an access token using the OAuth 2.0 protocol

Time:01-17

how to Use the client ID and client secret to obtain an access token using the OAuth 2.0 protocol

please give me an example

CodePudding user response:

you can also get token via ajax run this code in php file

<p id="demo"></p>
<button type="button" onclick="loadDoc()">Request data</button>
   

Request data

<script>
function loadDoc() {
  const xhttp = new XMLHttpRequest();
  xhttp.onload = function() {
    document.getElementById("demo").innerHTML = this.responseText;
  }
  xhttp.open("POST", "https://www.googleapis.com/oauth2/v4/token");
  xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  xhttp.send("code=<?=$_REQUEST['code']?>&client_id=your_client_id&client_secret=your_client_secret&redirect_uri=your_redriction_url&grant_type=authorization_code");
}
</script>  
  • Related