PHP code example of seinopsys / oauth2-deviantart

1. Go to this page and download the library: Download seinopsys/oauth2-deviantart library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

seinopsys / oauth2-deviantart example snippets


$provider = new SeinopSys\OAuth2\Client\Provider\DeviantArtProvider([
	'clientId' => 'client_id',
	'clientSecret' => 'client_secret',
	'redirectUri' => 'http://example.com/auth',
]);

$accessToken = $provider->getAccessToken('authorization_code', [
	'code' => $_GET['code'],
	'scope' => ['user','browse'] // optional, defaults to ['user']
]);
$actualToken = $accessToken->getToken();
$refreshToken = $accessToken->getRefreshToken();

// Once it expires

$newAccessToken = $provider->getAccessToken('refresh_token', [
	'refresh_token' => $refreshToken
]);

$provider = new SeinopSys\OAuth2\Client\Provider\DeviantArtProvider([
	'clientId' => 'client_id',
	'clientSecret' => 'client_secret',
	'redirectUri' => 'http://example.com/auth',
	'pkceMethod' => SeinopSys\OAuth2\Client\Provider\DeviantArtProvider::PKCE_METHOD_S256,
]);

// Starting the flow
$authUrl = $provider->getAuthorizationUrl();
$_SESSION['oauth2state'] = $provider->getState();
$_SESSION['oauth2pkceCode'] = $provider->getPkceCode();
header("Location: $authUrl");

// In the callback, after checking the state
$provider->setPkceCode($_SESSION['oauth2pkceCode']);
$accessToken = $provider->getAccessToken('authorization_code', [
	'code' => $_GET['code'],
]);