69 lines
2.3 KiB
PHP
69 lines
2.3 KiB
PHP
<?php declare(strict_types=1);
|
|
// OAuth2AuthorizationRequest.php
|
|
// Created: 2024-11-16
|
|
// Updated: 2024-11-16
|
|
|
|
namespace Flashii\OAuth2;
|
|
|
|
/**
|
|
* OAuth2 authorisation request response.
|
|
*/
|
|
final class OAuth2AuthorizationRequest {
|
|
/**
|
|
* @param string $deviceCode Authorisation request code.
|
|
* @param string $userCode Code for user entry.
|
|
* @param string $verificationUri Verification URI sans code.
|
|
* @param string $verificationUriComplete Verification URI but with code.
|
|
* @param int $expiresIn Amount of seconds until the thing expires.
|
|
* @param int $interval Interval of seconds to check at.
|
|
*/
|
|
public function __construct(
|
|
private string $deviceCode,
|
|
private string $userCode,
|
|
private string $verificationUri,
|
|
private string $verificationUriComplete,
|
|
private int $expiresIn,
|
|
private int $interval
|
|
) {}
|
|
|
|
public function getDeviceCode(): string {
|
|
return $this->deviceCode;
|
|
}
|
|
|
|
public function getUserCode(): string {
|
|
return $this->userCode;
|
|
}
|
|
|
|
public function getVerificationUri(): string {
|
|
return $this->verificationUri;
|
|
}
|
|
|
|
public function getVerificationUriComplete(): string {
|
|
return $this->verificationUriComplete;
|
|
}
|
|
|
|
public function getExpiresIn(): int {
|
|
return $this->expiresIn;
|
|
}
|
|
|
|
public function getInterval(): int {
|
|
return $this->interval;
|
|
}
|
|
|
|
/**
|
|
* Decodes an object into this proper object.
|
|
*
|
|
* @param object $info
|
|
* @return OAuth2AuthorizationRequest
|
|
*/
|
|
public static function decode(object $info): self {
|
|
return new static(
|
|
isset($info->device_code) && is_string($info->device_code) ? $info->device_code : '',
|
|
isset($info->user_code) && is_string($info->user_code) ? $info->user_code : '',
|
|
isset($info->verification_uri) && is_string($info->verification_uri) ? $info->verification_uri : '',
|
|
isset($info->verification_uri_complete) && is_string($info->verification_uri_complete) ? $info->verification_uri_complete : '',
|
|
isset($info->expires_in) && is_int($info->expires_in) ? $info->expires_in : 600,
|
|
isset($info->interval) && is_int($info->interval) ? $info->interval : 5
|
|
);
|
|
}
|
|
}
|