Socialite Battle.net Provider
This library contains a Battle.net OAuth 2 Provider for Laravels Socialite Authentication layer.
Installation
First of all, make sure you follow the installation instructions listed on laravel/socialite.
To get started with this provider, first add the library to the requirements listed in your composer.json
file:
composer require padarom/battlenet-socialite
After installing the library, register its service provider in your config/app.php
to your providers
array:
'providers' => [
// Other service providers...
Padarom\BattleNet\Socialite\\BattlenetServiceProvider::class,
],
Configuration
Before using it, you will need to add your Battle.net application credentials to your config/services.php
file:
'battlenet' => [
'client_id' => 'your-battlenet-app-id',
'client_secret' => 'your-battlenet-app-secret',
'redirect' => 'https://your-callback-url',
'region' => 'eu',
],
A description on how to create a Battle.net application can be found in the User and App Registration Guide.
Basic Usage
This example is derived from the previously mentioned laravel/socialite package, adjusted for this provider.
<?php
namespace App\Http\Controllers\Auth;
use Socialite;
class AuthController extends Controller
{
/**
* Redirect the user to the Battle.net authentication page.
*
* @return Response
*/
public function redirectToProvider()
{
return Socialite::driver('battle.net')->redirect();
}
/**
* Obtain the user information from Battle.net.
*
* @return Response
*/
public function handleProviderCallback()
{
$user = Socialite::driver('battle.net')->user();
// $user->token;
}
}
Then, route your requests to these controller methods:
Route::get('auth/github', 'Auth\AuthController@redirectToProvider');
Route::get('auth/github/callback', 'Auth\AuthController@handleProviderCallback');