<?php

namespace AuthStack\OIDC;

use Lcobucci\JWT\Signer;
use AuthStack\OIDC\Exception\TokenException;

/**
 * @param string $token
 * @param Signer $signer
 * @param string $public_key
 * @return IDToken|string
 * @throws TokenException
 */
function id_token(string $token, Signer $signer, string $public_key): IDToken
{
    $token = new IDToken($token);

    $verified = $token->verify($signer, $public_key);

    if(!$verified)
    {
        throw new TokenException("Signature can't be verified.");
    }

    return $token;
}