解码OpenID id_token - JWT

时间:2017-04-06 19:30:02

标签: php laravel laravel-5 laravel-5.1 jwt

我有 OpenID Auth服务器的id_token,

eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6ImJlbnVfMTQyNjE1LTEwMDEyMDE3In0.eyJpc3MiOiJodHRwczovL2xvZ2luLnVhdC50ZWxlbmV0LmJlL29wZW5pZCIsImlhdCI6MTQ5MTUwNjU0NCwiYXVkIjoiYmVudSIsInN1YiI6Ijg4ODI1NGU4LWYxZTgtNDk1Ni04NmZhLWE2YzBmNjFhNjQyMSIsInByZWZlcnJlZF91c2VybmFtZSI6Im1hbmFnZXItdGVsZW5ldGxvZ2luQGdtYWlsLmNvbSIsImh0dHA6Ly90ZWxlbmV0LmJlL2NsYWltcy9jdXN0b21lcl9udW1iZXIiOiI5MjkxODY2NDIiLCJodHRwOi8vdGVsZW5ldC5iZS9jbGFpbXMvaWRlbnRpdHkiOiIxMTAwMDE5OSIsImdpdmVuX25hbWUiOiJNYW5hZ2VyMSIsImZhbWlseV9uYW1lIjoiVGVsZW5ldCBsb2dpbjEiLCJodHRwOi8vdGVsZW5ldC5iZS9jbGFpbXMvY3JlZGVudGlhbCI6IjEzNTkxMDc0IiwiZXhwIjoxNDkxNTA4MzQ0LCJhdXRoX3RpbWUiOjE0OTE1MDY1NDQsIm5vbmNlIjoiMzg5MDkxMzYtZDZiZC00ZjZmLThkNTYtMGM1ZDJhMGZkYjRjIiwiaHR0cDovL3RlbGVuZXQuYmUvY2xhaW1zL3JvbGVzIjpbeyJuYW1lIjoiTWVtYmVyIiwicmVmZXJlbmNlcyI6W3sibmFtZSI6IkRUVmxpbmUiLCJ2YWx1ZSI6IkRUVjE1NDg0NjEiLCJkb21haW4iOiJPQVNJUyIsImVudGl0eSI6IklkZW50aXR5In0seyJuYW1lIjoiQ3VzdG9tZXJfTnVtYmVyIiwidmFsdWUiOiI5MjkxODY2NDIiLCJkb21haW4iOiJPQVNJUyIsImVudGl0eSI6IkN1c3RvbWVyIn1dfV19.NB_Rziv2d5OxDAvs0qQI0m_6Q2DG22DkTKsstNMHiWqFo_LmrmuvsXASnaH3MY7XCwXl0wrTsM5C6rVQiVKmvtIHvAd8TmMfiXIcgnvP-R43wEOXoyATyWEYMw_KWmJkqnanFgEDYpeNeCglO864fLXcjZ9VLpEnerHKtdLjWAL13qhy1kK38UlHeCvAB-sUp62-EBvUfVLj2WCOh011myZZqqc83-HwHk0ddXT74JTm6gCkF0IVal9Ui7ikJ6xlsrp3IR2hNG805D-cIoGf5nk3CDRfO1tGeV1m-bI79wTt_KyOlf3pc30ey0oFdFp0Zo0BurjDebh0LpTUCYi5cQ

当我测试解码时:

https://jwt.io/

我得到了

enter image description here

我想知道,是否有办法以编程方式解码此解码?

是否有一个Laravel框架可以帮助我实现这一目标?

我希望能够在我的id_token上获得有效负载。

2 个答案:

答案 0 :(得分:2)

JWT由3个由点分隔的部分组成。标头和有效负载只是base64编码的JSON结构。解决方案应该是这样的:

$jwt_payload = base64_decode('base64_string');

还请检查此问题How to decode base64 in laravel 5.3,了解如何解决laravel中的Base64编码数据。希望这会有所帮助。

答案 1 :(得分:2)

我推荐这个库:https://github.com/lcobucci/jwt

您可以在令牌字符串

上实例化[bits 16] [org 0x7c00] xor ax, ax ; AX=0 mov ds, ax mov es, ax mov ss, ax mov sp, 0x7c00 ; Place stack before the bootloader. Grows down from 0x0000:0x7c00 mov si, HelloString call print_string mov di, name call read_name mov si, name call print_string cli ; Turn off interrupts endloop: hlt ; Halt processor until next interrupt encountered jmp endloop ; Jump back just in case we get an MNI (non-maskable interrupt) read_name: read_char: mov ah, 0h ; read character from keyboard int 0x16 ; store it in AL cmp al, 0x0d ; check for enter je stop_reading mov [di], al ; save it in the buffer inc di ; next char mov ah, 0eh ; display character in AL int 0x10 ; echo it jmp read_char ; an so on stop_reading: mov byte [di], 0 ; NUL terminate buffer mov si, EoL call print_string ret print_char: mov ah, 0x0e ; one char mov bh, 0x00 ; page number mov bl, 0x07 ; font color int 0x10 ret print_string: next_char: mov al, [si] inc si or al, al jz exit_function call print_char jmp next_char exit_function: ret ;data HelloString db 'Enter your name', 0xd, 0xa, 0 name times 20 db 0 EoL db 0xd, 0xa, 0 times 510 - ($ - $$) db 0; dw 0xaa55 并调用Lcobucci\JWT\Parser方法
parse()

然后$parser = \Lcobucci\JWT\Parser(); $parsedToken = $this->parser->parse($token); 将成为$parsedToken类的对象,您可以在其中调用Lcobucci\JWT\Token方法获取令牌中的所有信息。