Skip to content

Commit 1151cb4

Browse files
committed
Added BattleNet example (#19)
1 parent aab6ec1 commit 1151cb4

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

examples/battlenet.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
/**
4+
* Example of retrieving an authentication token of the BattleNet service
5+
*
6+
* PHP version 5.4
7+
*
8+
* @author And <and.webdev@gmail.com>
9+
* @copyright Copyright (c) 2015 The authors
10+
* @license http://www.opensource.org/licenses/mit-license.html MIT License
11+
*/
12+
13+
use OAuth\Common\Consumer\Credentials;
14+
use OAuth\Common\Storage\Session;
15+
use OAuth\OAuth2\Service\BattleNet;
16+
17+
/**
18+
* Bootstrap the example
19+
*/
20+
require_once __DIR__ . '/bootstrap.php';
21+
22+
// Session storage
23+
$storage = new Session();
24+
25+
// Setup the credentials for the requests
26+
$credentials = new Credentials(
27+
$servicesCredentials[ 'battlenet' ][ 'key' ],
28+
$servicesCredentials[ 'battlenet' ][ 'secret' ],
29+
$currentUri
30+
);
31+
32+
// Instantiate the BattleNet service using the credentials, http client, storage mechanism for the token and profile scope
33+
/** @var BattleNet $battleNetService */
34+
$battleNetService = $serviceFactory->createService(
35+
'battlenet',
36+
$credentials,
37+
$storage,
38+
[BattleNet::SCOPE_SC2_PROFILE, BattleNet::SCOPE_WOW_PROFILE]
39+
);
40+
$battleNetService->setRegion('us');
41+
42+
if ($battleNetService->isGlobalRequestArgumentsPassed()) {
43+
// Retrieve a token and send a request
44+
$result = $battleNetService->retrieveAccessTokenByGlobReqArgs()->requestJSON('/account/user');
45+
46+
// Show some of the resultant data
47+
echo 'Your unique Battle.Net user id is: ' . $result[ 'id' ];
48+
} elseif (!empty($_GET[ 'go' ]) && $_GET[ 'go' ] === 'go') {
49+
$battleNetService->redirectToAuthorizationUri();
50+
} else {
51+
echo "<a href='$currentUri?go=go'>Login with Battle.Net!</a>";
52+
}

examples/init.example.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
'key' => '',
2020
'secret' => '',
2121
],
22+
'battlenet' => [
23+
'key' => '',
24+
'secret' => ''
25+
],
2226
'bitbucket' => [
2327
'key' => '',
2428
'secret' => '',

0 commit comments

Comments
 (0)