filsh / yii2-oauth2-server

A wrapper for implementing an OAuth2 Server(https://github.com/bshaffer/oauth2-server-php)
MIT License
332 stars 167 forks source link

ASK, how to get the public key to show to specific url #157

Open ahmadfadlydziljalal opened 7 months ago

ahmadfadlydziljalal commented 7 months ago

In doc:

<?php
namespace app\storage;

class PublicKeyStorage implements \OAuth2\Storage\PublicKeyInterface{

    private $pbk =  null;
    private $pvk =  null; 

    public function __construct()
    {
        $this->pvk =  file_get_contents('privkey.pem', true);
        $this->pbk =  file_get_contents('pubkey.pem', true); 
    }

    public function getPublicKey($client_id = null){ 
        return  $this->pbk;
    }

    public function getPrivateKey($client_id = null){ 
        return  $this->pvk;
    }

    public function getEncryptionAlgorithm($client_id = null){
        return 'RS256';
    }

}

Then , I wrote this action in a controller:

class OpenIdController extends BaseRestController
{

    /**
     * @throws InvalidConfigException
     */
    public function actionPublicKey()
    {
        /** @var Module $module */
        $module = Yii::$app->getModule('oauth2');
        die(Html::tag('pre', VarDumper::dumpAsString($module->getServer()->getStorage('public_key')->someWhat ? )));

    }

Thanks

ahmadfadlydziljalal commented 7 months ago

SOLVED

 /**
     * @throws InvalidConfigException
     */
    public function actionPublicKey()
    {
        /** @var Module $module */
        $module = Yii::$app->getModule('oauth2');
        return $module->getServer()
            ->getStorage('public_key')
            ->getPublicKey('some-client-id');
    }