Skip to content

Commit

Permalink
Merge pull request #923 from Sjors1985/922-Removed-Twitter-Facebook-L…
Browse files Browse the repository at this point in the history
…ogin

Remove Facebook- and Twittter-login
  • Loading branch information
heiglandreas authored Apr 24, 2024
2 parents d64200b + ce0754b commit e444670
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 189 deletions.
83 changes: 0 additions & 83 deletions app/src/User/AuthApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,87 +34,4 @@ public function login($username, $password, $clientId, $clientSecret)
}
return false;
}

/**
* Get a request token from the API from Twitter
*
* @param string $clientId OAuth client ID
* @param string $clientSecret OAuth client secret
* @return string|false The token
*/
public function getTwitterRequestToken($clientId, $clientSecret)
{
$url = $this->baseApiUrl . '/v2.1/twitter/request_token';
$params = [
'client_id' => $clientId,
'client_secret' => $clientSecret,
];

list($status, $result, $headers) = $this->apiPost($url, $params);
if ($status == 201) {
// we got one, data is actually in the body
$data = json_decode($result);
if ($data) {
$token = $data->twitter_request_tokens[0];
return $token->token;
}
}
return false;
}

/**
* Send Twitter verification token to the API to log us in
*
* @param string $clientId OAuth client ID
* @param string $clientSecret OAuth client secret
*/
public function verifyTwitter($clientId, $clientSecret, $token, $verifier)
{
$url = $this->baseApiUrl . '/v2.1/twitter/token';
$params = [
'client_id' => $clientId,
'client_secret' => $clientSecret,
'token' => $token,
'verifier' => $verifier,
];

list($status, $result, $headers) = $this->apiPost($url, $params);
if ($result) {
$data = json_decode($result);
if ($data) {
if (isset($data->access_token)) {
return $data;
}
}
}
return false;
}

/**
* Send Facebook verification code to the API to log us in
*
* @param string $clientId OAuth client ID
* @param string $clientSecret OAuth client secret
* @param string $code Code parameter from Facebook login
*/
public function verifyFacebook($clientId, $clientSecret, $code)
{
$url = $this->baseApiUrl . '/v2.1/facebook/token';
$params = [
'client_id' => $clientId,
'client_secret' => $clientSecret,
'code' => $code,
];

list($status, $result, $headers) = $this->apiPost($url, $params);
if ($result) {
$data = json_decode($result);
if ($data) {
if (isset($data->access_token)) {
return $data;
}
}
}
return false;
}
}
73 changes: 0 additions & 73 deletions app/src/User/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ protected function defineRoutes(\Slim\Slim $app)
->via('GET', 'POST')->name('user-password-reset');
$app->map('/user/new-password', [$this, 'newPassword'])
->via('GET', 'POST')->name('user-new-password');
$app->get('/user/twitter-login', [$this, 'loginWithTwitter'])->name('twitter-login');
$app->get('/user/twitter-access', [$this, 'accessTokenFromTwitter'])->name('twitter-callback');
$app->get('/user/facebook-access', [$this, 'accessTokenFromFacebook'])->name('facebook-callback');
$app->get('/user/:username', [$this, 'profile'])->name('user-profile');
$app->get('/user/:username/talks', [$this, 'profileTalks'])->name('user-profile-talks');
$app->get('/user/:username/events', [$this, 'profileEvents'])->name('user-profile-events');
Expand Down Expand Up @@ -787,76 +784,6 @@ public function newPassword()
);
}

/**
* This gets a request token via the API, and forwards the user
* to Twitter to log in and grant us access
*/
public function loginWithTwitter()
{
// ask the API for a request token
$config = $this->application->config('oauth');
$clientId = $config['client_id'];
$clientSecret = $config['client_secret'];

$authApi = $this->application->container->get(AuthApi::class);
$request_token = $authApi->getTwitterRequestToken($clientId, $clientSecret);

if ($request_token) {
// forward the user
header("Location: https://api.twitter.com/oauth/authenticate?oauth_token=" . $request_token);
exit;
}

$this->application->flash(
'error',
'We could not log you in with twitter'
);
$this->application->redirect('/');
}

/**
* The callback URL should point to here
*/
public function accessTokenFromTwitter()
{
$config = $this->application->config('oauth');
$request = $this->application->request();

// pass verification to the API so we can log in
$clientId = $config['client_id'];
$clientSecret = $config['client_secret'];

// handle incoming vars
$token = $request->get('oauth_token');
$verifier = $request->get('oauth_verifier');

$authApi = $this->application->container->get(AuthApi::class);
$result = $authApi->verifyTwitter($clientId, $clientSecret, $token, $verifier);

$this->handleLogin($result);
}

/**
* The Facebook callback URL returns here
*/
public function accessTokenFromFacebook()
{
$config = $this->application->config('oauth');
$request = $this->application->request();

// pass verification to the API so we can log in
$clientId = $config['client_id'];
$clientSecret = $config['client_secret'];

// handle incoming vars
$code = $request->get('code');

$authApi = $this->application->container->get(AuthApi::class);
$result = $authApi->verifyFacebook($clientId, $clientSecret, $code);

$this->handleLogin($result);
}

/**
* Process a user login result. If result is false, then we failed, otherwise
* update the session.
Expand Down
27 changes: 0 additions & 27 deletions app/src/View/FunctionsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,33 +152,6 @@ function ($start, $end, $format = 'd.m.Y', $separator = ' - ') {
}
}),

/**
* Create link to log in with Facebook
*/
new Twig_SimpleFunction(
'facebookLoginUrl',
function () use ($app) {
if (!$app->config('facebook') || empty($app->config('facebook')['app_id'])) {
// app_id isn't configured
return '';
}

$req = $app->request();
$redirectUrl = $req->getUrl();
$redirectUrl .= $app->urlFor('facebook-callback');

$url = 'https://www.facebook.com/dialog/oauth?';
$url .= http_build_query([
'scope' => 'email',
'client_id' => $app->config('facebook')['app_id'],
'redirect_uri' => $redirectUrl,
]);

return $url;
},
['is_safe' => ['html']]
),

/**
* Create a link to download a QR-Code for the given URL
*/
Expand Down
7 changes: 1 addition & 6 deletions app/templates/_common/login.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,11 @@
<input type="submit" class="btn btn-primary" value="Log in">
<a class="btn btn-link" href="{{ urlFor('user-register') }}">or register now</a>
</div>
<div class="form-group alternative-login">
<div class="already-registered">Already registered?</div>
<a href="{{ urlFor('twitter-login') }}"><img src="/img/sign-in-with-twitter.png" alt="Sign in with Twitter"></a>
<a href="{{ facebookLoginUrl() }}"><img src="/img/login-with-facebook.png" alt="Log In with Facebook"></a>
</div>
<div>
Problems logging in? <br>
<a href="{{ urlFor('user-resend-verification') }}">Resend&nbsp;welcome&nbsp;email</a><br>
<a href="{{ urlFor('user-password-reset') }}">Forgotten&nbsp;password</a><br>
<a href="{{ urlFor('user-username-reminder') }}">Forgotten&nbsp;username</a>
</div>
<input type="hidden" name="redirect" value="{{ redirect ? redirect : getCurrentUrl() }}">
</form>
</form>

0 comments on commit e444670

Please sign in to comment.