Add jwt handling, inspired by passport

This commit is contained in:
René Preuß
2021-03-30 23:19:36 +02:00
parent 32990da8a0
commit 14bf9d5480
14 changed files with 872 additions and 56 deletions

View File

@@ -32,6 +32,27 @@ class BitinflowAccounts
private static $baseUrl = 'https://accounts.bitinflow.com/api/';
/**
* The name for API token cookies.
*
* @var string
*/
public static $cookie = 'bitinflow_token';
/**
* Indicates if Bitinflow Accounts should ignore incoming CSRF tokens.
*
* @var bool
*/
public static $ignoreCsrfToken = false;
/**
* Indicates if Bitinflow Accounts should unserializes cookies.
*
* @var bool
*/
public static $unserializesCookies = false;
/**
* Guzzle is used to make http requests.
* @var \GuzzleHttp\Client
@@ -90,6 +111,49 @@ class BitinflowAccounts
]);
}
/**
* Get or set the name for API token cookies.
*
* @param string|null $cookie
* @return string|static
*/
public static function cookie($cookie = null)
{
if (is_null($cookie)) {
return static::$cookie;
}
static::$cookie = $cookie;
return new static;
}
/**
* Set the current user for the application with the given scopes.
*
* @param \Illuminate\Contracts\Auth\Authenticatable|Traits\HasBitinflowTokens $user
* @param array $scopes
* @param string $guard
* @return \Illuminate\Contracts\Auth\Authenticatable
*/
public static function actingAs($user, $scopes = [], $guard = 'api')
{
$user->withBitinflowAccessToken((object) [
'scopes' => $scopes
]);
if (isset($user->wasRecentlyCreated) && $user->wasRecentlyCreated) {
$user->wasRecentlyCreated = false;
}
app('auth')->guard($guard)->setUser($user);
app('auth')->shouldUse($guard);
return $user;
}
/**
* @param string $baseUrl
*