Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
GitHubController
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 3
12
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 connect
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
2
 connectCheck
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace App\Controller\Security;
6
7use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
8use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
9use Symfony\Component\HttpFoundation\RedirectResponse;
10use Symfony\Component\Routing\Attribute\Route;
11
12class GitHubController extends AbstractController
13{
14    public function __construct(private readonly ClientRegistry $clientRegistry) {}
15
16    /**
17     * Link to this controller to start the "connect" process.
18     */
19    #[Route(path: '/connect/github', name: 'connect_github_start', methods: ['GET'])]
20    public function connect(): RedirectResponse
21    {
22        return $this->clientRegistry
23            ->getClient('github')
24            ->redirect(
25                [
26                    'user:email', // the scopes you want to access
27                ],
28                []
29            );
30    }
31
32    /**
33     * After going to GitHub, you're redirected back here
34     * because this is the "redirect_route" you configured
35     * in config/packages/knpu_oauth2_client.yaml.
36     */
37    #[Route(path: '/connect/check/github', name: 'connect_github_check', methods: ['GET'])]
38    public function connectCheck(): RedirectResponse
39    {
40        return $this->redirectToRoute('default');
41    }
42}