mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-11-27 01:02:12 +05:30
Add code challenge verifiers
This commit is contained in:
parent
6a1645aebc
commit
970df8f34b
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Lukáš Unger <lookymsc@gmail.com>
|
||||
* @copyright Copyright (c) Lukáš Unger
|
||||
* @license http://mit-license.org/
|
||||
*
|
||||
* @link https://github.com/thephpleague/oauth2-server
|
||||
*/
|
||||
|
||||
namespace League\OAuth2\Server\CodeChallengeVerifiers;
|
||||
|
||||
interface CodeChallengeVerifierInterface
|
||||
{
|
||||
/**
|
||||
* Return code challenge method.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMethod();
|
||||
|
||||
/**
|
||||
* Verify the code challenge.
|
||||
*
|
||||
* @param string $codeVerifier
|
||||
* @param string $codeChallenge
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function verifyCodeChallenge($codeVerifier, $codeChallenge);
|
||||
}
|
36
src/CodeChallengeVerifiers/PlainVerifier.php
Normal file
36
src/CodeChallengeVerifiers/PlainVerifier.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Lukáš Unger <lookymsc@gmail.com>
|
||||
* @copyright Copyright (c) Lukáš Unger
|
||||
* @license http://mit-license.org/
|
||||
*
|
||||
* @link https://github.com/thephpleague/oauth2-server
|
||||
*/
|
||||
|
||||
namespace League\OAuth2\Server\CodeChallengeVerifiers;
|
||||
|
||||
class PlainVerifier implements CodeChallengeVerifierInterface
|
||||
{
|
||||
/**
|
||||
* Return code challenge method.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMethod()
|
||||
{
|
||||
return 'plain';
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify the code challenge.
|
||||
*
|
||||
* @param string $codeVerifier
|
||||
* @param string $codeChallenge
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function verifyCodeChallenge($codeVerifier, $codeChallenge)
|
||||
{
|
||||
return hash_equals($codeVerifier, $codeChallenge);
|
||||
}
|
||||
}
|
39
src/CodeChallengeVerifiers/S256Verifier.php
Normal file
39
src/CodeChallengeVerifiers/S256Verifier.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Lukáš Unger <lookymsc@gmail.com>
|
||||
* @copyright Copyright (c) Lukáš Unger
|
||||
* @license http://mit-license.org/
|
||||
*
|
||||
* @link https://github.com/thephpleague/oauth2-server
|
||||
*/
|
||||
|
||||
namespace League\OAuth2\Server\CodeChallengeVerifiers;
|
||||
|
||||
class S256Verifier implements CodeChallengeVerifierInterface
|
||||
{
|
||||
/**
|
||||
* Return code challenge method.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMethod()
|
||||
{
|
||||
return 'S256';
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify the code challenge.
|
||||
*
|
||||
* @param string $codeVerifier
|
||||
* @param string $codeChallenge
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function verifyCodeChallenge($codeVerifier, $codeChallenge)
|
||||
{
|
||||
return hash_equals(
|
||||
strtr(rtrim(base64_encode(hash('sha256', $codeVerifier, true)), '='), '+/', '-_'),
|
||||
$codeChallenge
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user