我目前正在尝试在一些 akka-http 服务中构建 oAuth 2 身份验证。我想使用jwt-scala和 jwtCirce 来解码 Web 令牌。在控制台(以及我的测试)中尝试它时,我得到了错误Failure(java.lang.IllegalArgumentException: Illegal base64 character 2d)
这是描述问题的控制台会话:
scala> import java.time.Instant
import java.time.Instant
scala> import cats.syntax.either._
import cats.syntax.either._
scala> import io.circe._, syntax._, jawn.{parse => jawnParse}
import io.circe._
import syntax._
import jawn.{parse=>jawnParse}
scala> import pdi.jwt.{JwtCirce, JwtAlgorithm, JwtClaim}
import pdi.jwt.{JwtCirce, JwtAlgorithm, JwtClaim}
scala> val privateKey = "MIIEpgIBAAKCAQEAvIWfxSuGXxUuVMHQaChB/bCOlRn3pJPZUHsC4vhcaRv7v9wWnZyVx36dsQ/BHB2icmfeVln6kXL8PSCAJcavO1cIXeHlJO9wlKKejZCcyu8v4dQn8bEFllFaIHt5yjfT9Kq3Tq5AJ9a6AdzkmUiGdrmMqQcHV0zKLMTdLLIl2sN72ZmkWCkilMacdLBjrLhIawOUfCngG57axiXEFOqjhWsumBEeV5yqIfgW335ASMSttEXtc418IRotD0rQEIX4UH78XuV6Lo7BWDjiAz0F0haMnPJhC/AMQGvgk2Yg6EVYxRueMMm6enNQ3ml0BJ71KmB/yFiivA1s6+f9PGvYMwIDAQABAoIBAQCerXIvSVVOjstyd7ftE4WH/KXmhfbVRcSyYvepBxbxOaaKdLtsajH/umkMcZA/FAp5dUfFMvMencQFx2dVZIh1z+mw68QtdIQz9zSxPzlZ7j1FPYdpfXCQd2T+1i9Kr/bthwvHZA+H+MqTatPW2R6kq8TjOJFLP80kJYdsaX5HRLMbZQyfVvMNpb9Qb1iSTY7r3dHsZ99x0GGkEiY4+g3qhPri2Fn+N64+CBg8EXYM5OWGOFUgtGn+xKP8YJW2t3roOQlNcXcyBR4WZebrUr2Vtqm+I5OKYDz2ED+KQR9LvEq/mQtCk8Opqc/55nMbRCsI+v3uq91dI+Xmr360kNyxAoGBAPOeQRavLMR3ebeL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G57axiXEFOqjhWsumBEeV5yqIfgW335ASMSttEXtc418IRotD0rQEIX4UH78XuV6Lo7BWDjiAz0F0haMnPJhC/AMQGvgk2Yg6EVYxRueMMm6enNQ3ml0BJ71KmB/yFiivA1s6+f9PGvYMwIDAQABAoIBAQCerXIvSVVOjstyd7ftE4WH/KXmhfbVRcSyYvepBxbxOaaKdLtsajH/umkMcZA/FAp5dUfFMvMencQFx2dVZIh1z+mw68QtdIQz9zSxPzlZ7j1FPYdpfXCQd2T+1i9Kr/bthwvHZA+H+MqTatPW2R6kq8TjOJFLP80kJYdsaX5HRLMbZQyfVvMNpb9Qb1iSTY7r3dHsZ99x0GGkEiY4+g3qhPri2Fn+N64+CBg8EXYM5OWGOFUgtGn+xKP8YJW2t3roOQlNcXcyBR4WZebrUr2Vtqm+I5OKYDz2ED+KQR9LvEq/mQtCk8Opqc/55nMbRCsI+v3uq91dI+Xmr360kNyxAoGBAPOeQRavLMR3ebeLfa1VZRiMg6uH2004zs02kEPcvkcOceUHGwJ4NB0yPPWb...
scala> val algo = JwtAlgorithm.RS384
algo: pdi.jwt.JwtAlgorithm.RS384.type = RS384
scala> val Right(claimJson) = jawnParse(s"""{"expires":${Instant.now.getEpochSecond}}""")
claimJson: io.circe.Json =
{
"expires" : 1484816589
}
scala> val Right(header) = jawnParse( """{"typ":"JWT","alg":"RS384"}""")
header: io.circe.Json =
{
"typ" : "JWT",
"alg" : "RS384"
}
scala> val token = JwtCirce.encode(header, claimJson, privateKey)
token: String = eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzM4NCJ9.eyJleHBpcmVzIjoxNDg0ODE2NTg5fQ.EQElbsrEtfxu1NLjYehKkpxiJrBMAcMx-pV7Zf0s_AHEBt3pBoEguxmcBYLdxPW9h_0K45pd2awee5dxRSDpC4Hdf4RN731IY0Ya8UfGe8og27t7qHuTVqm0jVGVlCOhtF4JQpu6TX84uvfxvJb0re8flc_MzLWkL78kkwBFO6AfyDSkGNHRdYJ3z_vi2LpUCSHXWPRluKAv8dZ32u4MIYaLlQYfpSW4k7aUy7Oopa-eN2albr1icf-Eik9AtpdZS3z8BosgVuOWg3_UlwFVFnKhU73t5ogwN--KEnXDkf66DcG2VrqT_oxHtskF1CG6dMxy5wMWPfEpL-emHsBrmg
scala> val pubKey = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC8hZ/FK4ZfFS5UwdBoKEH9sI6VGfekk9lQewLi+FxpG/u/3BadnJXHfp2xD8EcHaJyZ95WWfqRcvw9IIAlxq87Vwhd4eUk73CUop6NkJzK7y/h1CfxsQWWUVoge3nKN9P0qrdOrkAn1roB3OSZSIZ2uYypBwdXTMosxN0ssiXaw3vZmaRYKSKUxpx0sGOsuEhrA5R8KeAbntrGJcQU6qOFay6YER5XnKoh+BbffkBIxK20Re1zjXwhGi0PStAQhfhQfvxe5XoujsFYOOIDPQXSFoyc8mEL8AxAa+CTZiDoRVjFG54wybp6c1DeaXQEnvUqYH/IWKK8DWzr5/08a9gz"
pubKey: String = ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC8hZ/FK4ZfFS5UwdBoKEH9sI6VGfekk9lQewLi+FxpG/u/3BadnJXHfp2xD8EcHaJyZ95WWfqRcvw9IIAlxq87Vwhd4eUk73CUop6NkJzK7y/h1CfxsQWWUVoge3nKN9P0qrdOrkAn1roB3OSZSIZ2uYypBwdXTMosxN0ssiXaw3vZmaRYKSKUxpx0sGOsuEhrA5R8KeAbntrGJcQU6qOFay6YER5XnKoh+BbffkBIxK20Re1zjXwhGi0PStAQhfhQfvxe5XoujsFYOOIDPQXSFoyc8mEL8AxAa+CTZiDoRVjFG54wybp6c1DeaXQEnvUqYH/IWKK8DWzr5/08a9gz
scala> JwtCirce.decodeJsonAll(token, pubKey, Seq(JwtAlgorithm.RS384))
res3: scala.util.Try[(io.circe.Json, io.circe.Json, String)] = Failure(java.lang.IllegalArgumentException: Illegal base64 character 2d)
有谁知道我做错了什么?
提前感谢您的帮助
干杯伯恩哈德