douou0977 2019-02-21 03:24
浏览 218

有没有办法对Laravel Passport创建的访问令牌进行非对称加密?

I am building an application which consists of 3 server. The first is my Authorization server, the second is my Database server(API) and finally my front-end server. I want to use asymmetrical encryption to encrypt the access token generated by my Authorization server so that sensitive data is not compromised and also so that i can send it along to my API and verify that the user making a request is actually who they claim to be. Is there anything in Laravel Passport that will make this implementation possible or is it better to use a third party library like PASETO or PHP JWT Framework??

Currently when i make a request to the Api

  1. The Api makes a call to the Authorization server to validate user using the access token.
  2. The Auth server validates the User
  3. If user validates, Api delivers the resources we asked for, else it return a validation error.

What i want to achieve with the Asymmetrical encryption is to eliminate the call to my Auth server before every request to the API and i read that i can achieve this using asymmetrical encryption.

  • 写回答

1条回答 默认 最新

  • dpa31905 2019-04-30 16:23
    关注

    To solve my problem I ended up using the SimpleJWT library to encrypt the data in the access token. The data is encrypted in the JWE claims.

      $headers = ['alg' => 'RSA-OAEP-256', 'enc' => 'A128CBC-HS256'];
      $access_token = {"sub": "1234567890", "name": "John Doe", "iat": 1516239022}
      // Creating JWE object with headers and claims
      $jwe = new \SimpleJWT\JWE($headers, $claims);
      $jwe_encrypted = $jwe->encrypt($foreing_server_public_key);
    

    I later decrypt the token using the python library JWCrypto. I am thinking about making the switch to Authlib JOSE Guide because it seems to have a broader community and support.

    //Decrypting JWE
    //Private key should be key pair of public key used to encrypt token
    jwetoken.deserialize(jwe_encrypted, key=private_key)
    //Validating Signature since passport signs tokens when generating them
    jwstoken.verify(auth_public_key)
    //Payload should contain encrypted data
    data = json.loads(jwstoken.payload.decode())
    >> {"sub": "1234567890", "name": "John Doe", "iat": 1516239022}
    
    评论

报告相同问题?

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来