Advertisement
Guest User

Untitled

a guest
Jul 9th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. <?php
  2.  
  3. //conexão sql
  4. $servername = "xxxt";
  5. $database = "xxxe";
  6. $username = "xxx";
  7. $password = "pxxx";
  8. //conectando
  9. $conn = mysqli_connect($servername, $username, $password, $database);
  10. //checando conexão
  11. if (!$conn) {
  12. die("Falha na conexão: " . mysqli_connect_error());
  13. }
  14.  
  15. echo "Conectado com sucesso!";
  16.  
  17. require __DIR__ . '/vendor/autoload.php';
  18.  
  19. session_start();
  20.  
  21. echo ('Main screen turn on!<br/><br/>');
  22.  
  23. $provider = new \Wohali\OAuth2\Client\Provider\Discord([
  24. 'clientId' => '4xxx4',
  25. 'clientSecret' => '7xxxx8',
  26. 'redirectUri' => 'hxxxp'
  27. ]);
  28.  
  29. if (!isset($_GET['code'])) {
  30.  
  31. // Step 1. Get authorization code
  32. $authUrl = $provider->getAuthorizationUrl();
  33. $_SESSION['oauth2state'] = $provider->getState();
  34. header('Location: ' . $authUrl);
  35.  
  36. // Check given state against previously stored one to mitigate CSRF attack
  37. } elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) {
  38.  
  39. unset($_SESSION['oauth2state']);
  40. exit('Invalid state');
  41.  
  42. } else {
  43.  
  44. // Step 2. Get an access token using the provided authorization code
  45. $token = $provider->getAccessToken('authorization_code', [
  46. 'code' => $_GET['code']
  47. ]);
  48.  
  49. // Show some token details
  50. echo '<h2>Token details:</h2>';
  51. echo 'Token: ' . $token->getToken() . "<br/>";
  52. echo 'Refresh token: ' . $token->getRefreshToken() . "<br/>";
  53. echo 'Expires: ' . $token->getExpires() . " - ";
  54. echo ($token->hasExpired() ? 'expired' : 'not expired') . "<br/>";
  55.  
  56. // Step 3. (Optional) Look up the user's profile with the provided token
  57. try {
  58.  
  59. $user = $provider->getResourceOwner($token);
  60.  
  61. // echo '<h2>Resource owner details:</h2>';
  62. // printf('Hello %s#%s!<br/><br/>', $user->getUsername(), $user->getDiscriminator());
  63.  
  64.  
  65. $dados = $user->toArray();
  66. $idd = $dados['id'];
  67. echo '<br>seu id é: ' . $dados['id'];
  68. $pegardados = "SELECT id FROM get_discord WHERE id = .$dados['id']";
  69. if (mysqli_query($conn, $pegardados)) {
  70. echo "dadospegos";}
  71. else {
  72. echo "Error: " . $sql . "<br>" . mysqli_error($conn);
  73. }
  74.  
  75. } catch (Exception $e) {
  76.  
  77. // Failed to get user details
  78. exit('Oh dear...');
  79.  
  80. }
  81. }
  82. // create $provider as in the initial example
  83. $existingAccessToken = getAccessTokenFromYourDataStore();
  84.  
  85. if ($existingAccessToken->hasExpired()) {
  86. $newAccessToken = $provider->getAccessToken('refresh_token', [
  87. 'refresh_token' => $existingAccessToken->getRefreshToken()
  88. ]);
  89.  
  90. // Purge old access token and store new access token to your data store.
  91. }
  92. // create $provider as in the initial example
  93. try {
  94.  
  95. // Try to get an access token using the client credentials grant.
  96. $accessToken = $provider->getAccessToken('client_credentials');
  97.  
  98. } catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) {
  99.  
  100. // Failed to get the access token
  101. exit($e->getMessage());
  102.  
  103. }
  104.  
  105. mysqli_close($conn);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement