/**
  * Gets redirect uri (used in redirecting back to client)
  *
  * @return string
  */
 public function getRedirectUri()
 {
     $scopes = array_map(function (IScope $scope) {
         return $scope->getId();
     }, $this->accessToken->getScopes());
     $query = ['access_token' => $this->accessToken->getId(), 'expires_in' => $this->accessToken->getExpiresAt() - time(), 'token_type' => $this->tokenTypeName, 'scope' => join(' ', $scopes)];
     if ($this->state) {
         $query['state'] = $this->state;
     }
     ksort($query);
     // sort query params by key
     return $this->redirectUri . '#' . http_build_query($query);
 }
 function it_should_return_redirect_uri(IAccessToken $accessToken, IScope $scope1, IScope $scope2)
 {
     $accessToken->getExpiresAt()->willReturn(time() + 3600)->shouldBeCalled();
     $accessToken->getId()->willReturn('abcde')->shouldBeCalled();
     $accessToken->getScopes()->willReturn([$scope1, $scope2])->shouldBeCalled();
     $scope1->getId()->willReturn('scope1')->shouldBeCalled();
     $scope2->getId()->willReturn('scope2')->shouldBeCalled();
     $this->getRedirectUri()->shouldReturn('http://google.com#access_token=abcde&expires_in=3600&scope=scope1+scope2&state=state&token_type=Bearer');
 }