Anybody have use Invision Power OAuth? I'm getting error.
public function redirect(Request $request)
{
$client_id = '8c9eb146f013ddafedd3615873b92222';
$redirect_uri = 'https://ucp.gta-id.com/oauth/callback';
// Generate the authorization URL.
$authorization_url = 'https://gta-id.com/oauth/authorize?' . http_build_query([
'client_id' => $client_id,
'response_type' => 'code',
'redirect_uri' => $redirect_uri,
]);
return redirect($authorization_url);
}
public function callback(Request $request)
{
$response = Http::withHeaders([
'Content-Type' => 'application/x-www-form-urlencoded',
])->asForm()->post('https://gta-id.com/oauth/token', [
'grant_type' => 'authorization_code',
'code' => request()->input('code'),
'client_id' => "8c9eb146f013dXXXXXXX",
'client_secret' => "003aXXXXXXXXXXXXX",
'redirect_uri' => 'https://ucp.gta-id.com/oauth/callback',
]);
if ($response->failed()) {
// Handle the error response.
$error = $response->json('error');
$error_description = $response->json('error_description');
return response()->json(['error' => $error, 'description1' => $error_description]);
}
$access_token = $response->json('access_token');
if (!$access_token) {
// Handle the case where the response is missing the expected access token key.
return response()->json(['error' => 'Missing access token']);
}
$response = Http::withToken($access_token)->get('https://gta-id.com/api/users/me');
if ($response->failed()) {
// Handle the error response from the Invision Power API.
$error = $response->json('error');
$error_description = $response->json('error_description');
return response()->json(['error' => $error, 'description2' => $error_description]);
}
$username = $response->json('username');
$email = $response->json('email');
$id = Auth::id();
$user = User::where('id', $id)->first();
$user->invision_username = $username;
$user->invision_email = $email;
$user->save();
}