Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
colinhall17 authored and actions-user committed Sep 8, 2020
1 parent e0fbac8 commit e06fd62
Show file tree
Hide file tree
Showing 18 changed files with 217 additions and 224 deletions.
23 changes: 12 additions & 11 deletions src/Connection.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
<?php
namespace MacsiDigital\OAuth2;

use MacsiDigital\OAuth2\Traits\ForwardsCalls;
use MacsiDigital\OAuth2\Support\Providers\GenericProvider;
use MacsiDigital\OAuth2\Contracts\Connection as ConnectionContract;
use MacsiDigital\OAuth2\Support\Providers\GenericProvider;
use MacsiDigital\OAuth2\Traits\ForwardsCalls;

class Connection implements ConnectionContract
{
use ForwardsCalls;
use ForwardsCalls;

protected $provider;
protected $options;
protected $options;

/**
* Return if the OAuth2 implementation is authenticated.
*
* @param string $integration
* @return boolean
* @return bool
*
*/
public function authenticated($integration)
public function authenticated($integration)
{
$config = config($integration);
$token = new $config['tokenModel']($integration);

return $token->authenticated();
}

Expand All @@ -33,12 +34,13 @@ public function authenticated($integration)
* @return self
*
*/
public function withOptions($options)
{
public function withOptions($options)
{
$this->options = $options;
$this->provider = new GenericProvider($options);

return $this;
}
}

/**
* Handle dynamic method calls into the model. Forward calls to the provider
Expand All @@ -51,5 +53,4 @@ public function __call($method, $parameters)
{
return $this->forwardCallTo($this->provider, $method, $parameters);
}

}
}
3 changes: 0 additions & 3 deletions src/Contracts/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,4 @@

interface Connection
{



}
24 changes: 11 additions & 13 deletions src/Contracts/Token.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
<?php
namespace MacsiDigital\OAuth2\Contracts;

interface Token
interface Token
{
public function set($options);

public function set($options);
public function accessToken();

public function accessToken();
public function setAccessToken($token);

public function setAccessToken($token);
public function refreshToken();

public function refreshToken();
public function setRefreshToken($token);

public function setRefreshToken($token);
public function expires();

public function expires();
public function setExpires($timeStamp);

public function setExpires($timeStamp);
public function hasExpired();

public function hasExpired();

public function save();

}
public function save();
}
4 changes: 2 additions & 2 deletions src/Exceptions/AlreadyAuthenticatedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

class AlreadyAuthenticatedException extends Base
{
public function __construct($name)
public function __construct($name)
{
parent::__construct($name.' already authorised.');
}
}
}
3 changes: 1 addition & 2 deletions src/Exceptions/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

class Base extends Exception
{

}
}
4 changes: 2 additions & 2 deletions src/Exceptions/ConfigDoesntExistException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

class ConfigDoesntExistException extends Base
{
public function __construct($name)
public function __construct($name)
{
parent::__construct('No Config '.$name.' found.');
}
}
}
3 changes: 1 addition & 2 deletions src/Exceptions/IdentityProviderException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

class IdentityProviderException extends LeagueException
{

}
}
28 changes: 13 additions & 15 deletions src/Http/Controllers/AuthorisationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,29 @@

namespace MacsiDigital\OAuth2\Http\Controllers;

use Str;
use Illuminate\Http\Request;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Support\Facades\Cookie;
use Illuminate\Support\Facades\Storage;
use MacsiDigital\OAuth2\Contracts\Connection;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use MacsiDigital\OAuth2\Http\Requests\OAuth2Validation;
use MacsiDigital\OAuth2\Exceptions\IdentityProviderException;
use MacsiDigital\OAuth2\Exceptions\ConfigDoesntExistException;
use MacsiDigital\OAuth2\Exceptions\AlreadyAuthenticatedException;
use MacsiDigital\OAuth2\Exceptions\ConfigDoesntExistException;
use MacsiDigital\OAuth2\Exceptions\IdentityProviderException;
use MacsiDigital\OAuth2\Http\Requests\OAuth2Validation;

class AuthorisationController extends BaseController
{
use ValidatesRequests;

public function create(Connection $connection, $integration)
public function create(Connection $connection, $integration)
{
// Are we already authenticated?
if($connection->authenticated($integration)){
if ($connection->authenticated($integration)) {
throw new AlreadyAuthenticatedException($integration);
}
// If not then we need to ask for a token
$config = config($integration);

if($config == []){
if ($config == []) {
throw new ConfigDoesntExistException($integration);
}

Expand All @@ -40,16 +37,16 @@ public function create(Connection $connection, $integration)
return redirect()->away($url);
}

public function store(OAuth2Validation $request, Connection $connection, $integration)
public function store(OAuth2Validation $request, Connection $connection, $integration)
{
// Are we already authenticated?
if($connection->authenticated($integration)){
if ($connection->authenticated($integration)) {
throw new AlreadyAuthenticatedException($integration);
}

// If not then to prcess the token and save the access token
$config = config($integration);
if($config == []){
if ($config == []) {
throw new ConfigDoesntExistException($integration);
}

Expand All @@ -58,12 +55,13 @@ public function store(OAuth2Validation $request, Connection $connection, $integr
try {
// Try to get an access token using the authorization code grant.
$accessToken = $connection->getAccessToken('authorization_code', [
'code' => $request->code
'code' => $request->code,
]);

$token = new $config['tokenProcessor']($accessToken, $integration);

Cookie::forget('oauth2state');

return redirect($config['authorisedRedirect']);
} catch (IdentityProviderException $e) {
return redirect($config['failedRedirect'], ['error' => $e->getMessage()]);
Expand Down
9 changes: 3 additions & 6 deletions src/Integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

class Integration implements Model
{
/**
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'accessToken', 'refreshToken', 'expires', 'additional'
'name', 'accessToken', 'refreshToken', 'expires', 'additional',
];

/**
Expand All @@ -31,7 +31,4 @@ class Integration implements Model
protected $casts = [
'additional' => 'array',
];



}
}
2 changes: 1 addition & 1 deletion src/Providers/OAuth2ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class OAuth2ServiceProvider extends ServiceProvider
{
public function boot()
public function boot()
{
$this->loadRoutesFrom(__DIR__.'/../../routes/web.php');

Expand Down
10 changes: 5 additions & 5 deletions src/Support/AuthorisationProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

class AuthorisationProcessor
{
public function __construct($accessToken, $integration)
public function __construct($accessToken, $integration)
{
$config = config($integration);
$token = $config['tokenModel'];
$config = config($integration);
$token = $config['tokenModel'];

return (new $token($integration))->updateAccessToken($accessToken);
}

}
}
3 changes: 1 addition & 2 deletions src/Support/Providers/GenericProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@

class GenericProvider extends LeagueGenericProvider
{

}
}
Loading

0 comments on commit e06fd62

Please sign in to comment.