Skip to content

Commit

Permalink
Removed Authorization-Update header flow from social login and fixed …
Browse files Browse the repository at this point in the history
…tests for query param
  • Loading branch information
zakhenry committed Aug 4, 2015
1 parent 94a907c commit d076b97
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion api/app/Http/Controllers/AuthController.php
Expand Up @@ -206,7 +206,7 @@ public function handleProviderCallback($provider, Socialite $socialite, UserRepo
$token = $this->jwtAuth->fromUser($user, ['method' => $provider]);
$returnUrl = $socialite->with($provider)->getCachedReturnUrl() . '?jwtAuthToken=' . $token;

$response = $this->getResponse()->header('Authorization-Update', 'Bearer '.$token);
$response = $this->getResponse();
$response->redirect($returnUrl, 302);
return $response;
}
Expand Down
32 changes: 24 additions & 8 deletions api/tests/integration/AuthTest.php
Expand Up @@ -389,17 +389,24 @@ public function testProviderCallbackExistingUser()

$this->get('/auth/social/facebook/callback');


$this->assertResponseStatus(302);

$this->assertTrue($this->response->headers->has('location'), 'Response has location header.');
$locationHeader = $this->response->headers->get('location');

// Get the returned token
$token = str_replace('Bearer ', '', $this->response->headers->get('authorization-update'));
$tokenParam = parse_url($locationHeader, PHP_URL_QUERY);
$this->assertStringStartsWith('jwtAuthToken=', $tokenParam);

$token = str_replace('jwtAuthToken=', '', $tokenParam);

$token = new Token($token);
$jwtAuth = $this->app->make('Tymon\JWTAuth\JWTAuth');
$decoded = $jwtAuth->decode($token)->toArray();

$this->assertResponseStatus(302);
$array = json_decode($this->response->getContent(), true);
$this->assertEquals('facebook', $decoded['method']);
$this->assertTrue($this->response->headers->has('location'), 'Response has location header.');
$this->assertStringStartsWith('http://foo.bar', $this->response->headers->get('location'));
$this->assertStringStartsWith('http://foo.bar', $locationHeader);

// Assert that the social login was created
$user = User::find($user->user_id);
Expand Down Expand Up @@ -427,14 +434,23 @@ public function testProviderCallbackNewUser()

$this->get('/auth/social/facebook/callback');



$this->assertResponseStatus(302);

$this->assertTrue($this->response->headers->has('location'), 'Response has location header.');
$locationHeader = $this->response->headers->get('location');

// Get the returned token
$token = str_replace('Bearer ', '', $this->response->headers->get('authorization-update'));
$tokenParam = parse_url($locationHeader, PHP_URL_QUERY);
$this->assertStringStartsWith('jwtAuthToken=', $tokenParam);

$token = str_replace('jwtAuthToken=', '', $tokenParam);

$token = new Token($token);
$jwtAuth = $this->app->make('Tymon\JWTAuth\JWTAuth');
$decoded = $jwtAuth->decode($token)->toArray();

$this->assertResponseStatus(302);
$array = json_decode($this->response->getContent(), true);
$this->assertEquals('facebook', $decoded['method']);
$this->assertTrue($this->response->headers->has('location'), 'Response has location header.');
$this->assertStringStartsWith('http://foo.bar', $this->response->headers->get('location'));
Expand Down

0 comments on commit d076b97

Please sign in to comment.