I'm trying to connect users in my php app to 23 and Me api but having issues when trying to use the provided token. I can successfully get the token with the following http action:
<a href="https://api.23andme.com/authorize/?redirect_uri={{ env('APP_URL') }}/receive_code/&response_type=code&client_id={{ env('DNA_ID') }}&scope=basic names email">Connect with 23andMe</a>
Which redirects to the following controller and successfully returns a token which I store in the users table:
public function connectDNA()
{
$code = $_GET["code"];
$client = new Client();
$result = $client->post('https://api.23andme.com/token/', [
'form_params' => [
'client_id' => env('DNA_ID'),
'client_secret' => env('DNA_SECRET'),
'grant_type' => 'authorization_code',
'code' => $code,
'redirect_uri' => 'http://localhost:8000/receive_code/',
'scope' => 'basic names email'
]
]);
$contents = $result->getBody()->getContents();
$contents = json_decode($contents);
$user = Auth::user();
$user->dna_token = $contents->access_token;
$user->save();
return redirect('/home');
}
The problem is when I try to use that token to access the 23 and me API with guzzle, which I suspect is because I don't know how to structure the call. I've tried multiple variations on the following:
$result = $client->get('https://api.23andme.com/3/account/', [
'Authorization' => $user->dna_token
]);
return $result;
UPDATE: The issue seems to be how I'm formatting guzzle. When I curl:
curl "https://api.23andme.com/3/account/" \ > -H "Authorization: Bearer demo_oauth_token"
The API returns a test result, how would I format the above in Guzzle?