Last active
August 22, 2016 02:45
-
-
Save Tjoosten/b1f691bb0b9b4e8be1fce9c7c49166af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"error":"invalid_client","message":"Client authentication failed"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
id: 3 | |
token: 9obelPLLNTDvHTdbS5ZuLYCDqNw6PkNc4Opi6JJj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
|-------------------------------------------------------------------------- | |
| Web Routes | |
|-------------------------------------------------------------------------- | |
| | |
| This file is where you may define all of the routes that are handled | |
| by your application. Just tell Laravel the URIs it should respond | |
| to using a Closure or controller method. Build something great! | |
| | |
*/ | |
use Illuminate\Http\Request; | |
// First route that user visits on consumer app | |
Route::get('/', function () { | |
// Build the query parameter string to pass auth information to our request | |
$query = http_build_query([ | |
'client_id' => 3, | |
'redirect_uri' => 'http://localhost:7000/callback', | |
'response_type' => 'code', | |
'scope' => '*' | |
]); | |
// Redirect the user to the OAuth authorization page | |
return redirect('http://localhost:8000/oauth/authorize?' . $query); | |
}); | |
// Route that user is forwarded back to after approving on server | |
Route::get('callback', function (Request $request) { | |
$http = new GuzzleHttp\Client; | |
$response = $http->post('http://localhost:8000/oauth/token', [ | |
'form_params' => [ | |
'grant_type' => 'authorization_code', | |
'client_id' => '3', | |
'client_secret' => '9obelPLLNTDvHTdbS5ZuLYCDqNw6PkNc4Opi6JJj', | |
'redirect_uri' => 'http://localhost:7000/callback', | |
'code' => $request->code// Get code from the' | |
] | |
]); | |
return json_decode((string) $response->getBody(), true)['access_token']; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment