Are you using JWT or Reference tokens?
Reference tokens are verified by the authority-holding Identity-server. It might be difficult to use different identity-servers and verify tokens supplied by another one than the one verifying it. If you are using JWT you can use the Discovery-Endpoint to capture the public key. Then you should be able to use this to verify the signature...
You can do this like:
// Define the client to access the IdentityServer Discovery-Endpoint
var discos = new DiscoveryClient(ConfigurationManager.AppSettings["IdentityserverLocation"]);
var disco = await discos.GetAsync();
// get the public key from the discovery-endpoint
var keys = disco.KeySet.Keys;
//Build the authorization request
//param: Disco.AuthorizeEndpoint --> retrieves the authorization url from the identityserver
var request = new AuthorizeRequest(disco.AuthorizeEndpoint);
var url = request.CreateAuthorizeUrl(
clientId: ConfigurationManager.AppSettings["ClientId"],
responseType: "id_token",
scope: "openid profile email",
responseMode: OidcConstants.ResponseModes.FormPost,
redirectUri: ConfigurationManager.AppSettings["RedirectUrl"],
state: CryptoRandom.CreateUniqueId(),
nonce: CryptoRandom.CreateUniqueId());
//Try to initiate validation
try
{
// Check if the token data exists in the request, parse is to a correct token
var idToken = Request.Form.Get("id_token");
JwtSecurityToken j = new JwtSecurityToken(idToken);
var keylist = new List<SecurityKey>();
foreach (var webKey in disco.KeySet.Keys)
{
var exp = Base64Url.Decode(webKey.E);
var mod = Base64Url.Decode(webKey.N);
var key = new RsaSecurityKey(new RSAParameters() { Modulus = mod, Exponent = exp });
keylist.Add(key);
}
//define the parameters for validation of the token
var parameters = new TokenValidationParameters
{
ValidIssuer = disco.Issuer,
ValidAudience = "viper",
IssuerSigningKeys = keylist,
};
var handler = new JwtSecurityTokenHandler();
handler.InboundClaimTypeMap.Clear();
//validate the token using the defined parameters, return the token when validation is succesful
var user = handler.ValidateToken(j.RawData, parameters, out var validatedtoken);