Exemplo n.º 1
0
 public function authenticate(TokenInterface $token)
 {
     $email = $token->getCredentials();
     $user = $this->user_provider->loadOrCreateUser($email);
     // Log the user in
     $new_token = new GithubUserToken($user->getRoles());
     $new_token->setUser($user);
     $new_token->setAuthenticated(true);
     return $new_token;
 }
Exemplo n.º 2
0
 protected function attemptAuthentication(Request $request)
 {
     $client = new \Guzzle\Http\Client('https://github.com/login/oauth/access_token');
     $req = $client->post('', null, ['client_id' => 'f77f000b2dfc717ade2a', 'client_secret' => '42967a6f718a83e5f85ad609292a78fce81dd46d', 'code' => $request->query->get('code')])->setHeader('Accept', 'application/json');
     $res = $req->send()->json();
     $access_token = $res['access_token'];
     $client = new \Guzzle\Http\Client('https://api.github.com');
     $req = $client->get('/user');
     $req->getQuery()->set('access_token', $access_token);
     $res = $req->send()->json();
     $email = $res['email'];
     $token = new GithubUserToken();
     $token->setCredentials($email);
     return $this->authenticationManager->authenticate($token);
 }