Closed jennyphan closed 6 years ago
This was a type issue with golang, I converted to the correct type and it is working.
@jennyphan what was the type issue?
I had to convert to convert to rsa.PublicKey type. I used that ParseWithClaims and it finally worked. It seemed to be an issue with returning the right type.
rsaPublicKey := -----BEGIN CERTIFICATE----- xxxx -----END CERTIFICATE-----
block, _ := pem.Decode([]byte(rsaPublicKey))
var cert *x509.Certificate
cert, _ = x509.ParseCertificate(block.Bytes)
pub := cert.PublicKey.(*rsa.PublicKey)
token2, err := parser.ParseWithClaims(tokenB, &User{}, func(token jwt.Token) (interface{}, error) { // Don't forget to validate the alg is what you expect: if _, ok := token.Method.(jwt.SigningMethodRSA); !ok { return nil, fmt.Errorf("Unexpected signing method: %v", token.Header["alg"]) }
return pub, nil
})
I am trying to parse a JWT Token and I keep getting 'key is of invalid type'. I think that the encrypted key that I am passing in is invalid but I have tried so many different key values. I am using Azure B2C and I retrieved the public key but that did not work. I also used the kid value in the header and the secret key created in Azure for my registered apps. I am unable to resolve this issue. I am using RSA256. Variations of the key that I have tried
encryptedKey := "-----BEGIN CERTIFICATE-----xxxxxxxxxxxxxxxxxxxxxx-----END CERTIFICATE-----" where xxxxxx is public key from Azure encryptedKey := kid value from request header encryptedKey := secret key created in Azure Portal for my web api