問題描述
我有一個使用 OpenId Connect 的 Web 應用程序.我創建了一個自簽名證書,但它仍未由 CA 簽名.如何忽略簽名驗證?
I have an web application that is using OpenId Connect. I created a self signed certificate but it is still not signed by a CA. How can I ignore the signature validation?
這是我目前所擁有的:
它會拋出以下異常:
IDX10500:簽名驗證失敗.無法解決SecurityKeyIdentifier: 'SecurityKeyIdentifier
(
IsReadOnly = False,
計數 = 1,
子句[0] =System.IdentityModel.Tokens.NamedKeySecurityKeyIdentifierClause
)
',
令牌:'{"typ":"JWT","alg":"RS256","kid":"issuer_rsaKey"}.{"iss":...
IDX10500: Signature validation failed. Unable to resolve SecurityKeyIdentifier: 'SecurityKeyIdentifier (
IsReadOnly = False, Count = 1, Clause[0] = System.IdentityModel.Tokens.NamedKeySecurityKeyIdentifierClause
) ', token: '{"typ":"JWT","alg":"RS256","kid":"issuer_rsaKey"}.{"iss":...
推薦答案
不要忽略簽名,這很危險!
即使您使用自簽名證書,您也可以使用公鑰進行簽名驗證.
Even if you use a self-signed certificate, you will be able to use the public key for signature validation.
由于您使用的是 OpenId Connect,因此您應該能夠通過前往 /.well-known/jwks
獲取簽名證書的公鑰.
Since you are using OpenId Connect, you should be able to get the public key for your signing certificate by heading over to /.well-known/jwks
.
然后您可以像這樣設置驗證參數:
Then you can setup your validation parameters like this:
之后,你可以調用ValidateToken
:
您真的要忽略簽名嗎?
記住,如果你這樣做了,你怎么知道有人沒有篡改令牌內的數據?您可以輕松解碼 base64 url?? 編碼的有效負載并更改主題.如果您在應用程序中依賴它,您將遇到麻煩(提示:有人訪問其他人的數據)
Remember, if you do, how do you know someone didn't tamper with the data inside the token? You could easily decode the base64 url encoded payload and change the subject. And if you rely on that in your application, you'll be in trouble (hint: someone accessing someone else data)
你真的,真的想忽略它嗎?
您可以使用 ReadToken
并跳過所有驗證:
You can use ReadToken
and just skip every validation there is:
不要這樣做,這是不好的做法.
這篇關于忽略 JWT 中的簽名的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!