<?php

namespace AuthStack\OIDC;

use Lcobucci\JWT\Token;
use Lcobucci\JWT\Signer;
use Lcobucci\JWT\Parser;
use Lcobucci\JWT\Signer\Key;
use Lcobucci\JWT\Signer\Rsa\Sha256;

class IDToken
{
    protected $jwt;
    protected $token;

    public function __construct(string $jwt)
    {
        $this->jwt = $jwt;

        $this->token = (new Parser())->parse($jwt);
    }

    public function getJWT(): string
    {
        return $this->jwt;
    }

    /**
     * @return Token
     */
    public function getToken(): Token
    {
        return $this->token;
    }

    /**
     * @param Signer $signer
     * @param string $public_key
     * @return bool
     */
    public function verify(Signer $signer, string $public_key)
    {
        return $this->token->verify($signer, new Key($public_key));
    }
}