我需要从我正在处理的服务验证 azure jwt access_token。我们目前正在向https://graph.microsoft.com/beta/me发出请求。如果请求成功,则令牌有效。不幸的是,我们将无法继续这样做。
为此我尝试了多种想法。他们都没有成功。即使 jwt.io 也无法识别该签名,即使 jwtkid和jwk_urikid中的可用签名之一匹配。
基于这篇博文,我创建了以下解决方案(也可以在 github 上找到)。
我的实现与博客文章非常相似,但有一些更改:
#!/usr/bin/env python2
import jwt
import requests
import sys
from cryptography.x509 import load_pem_x509_certificate
from cryptography.hazmat.backends import default_backend
def get_public_key(access_token):
""" Retrieve public key for access token """
token_header = jwt.get_unverified_header(access_token)
res = requests.get('https://login.microsoftonline.com/common/.well-known/openid-configuration')
jwk_uri = res.json()['jwks_uri']
res = requests.get(jwk_uri)
jwk_keys = res.json()
x5c = None
# Iterate JWK keys and extract matching x5c chain
for key in jwk_keys['keys']: …Run Code Online (Sandbox Code Playgroud) 免责声明:
以下使用gcc 5.4.0编译并在Ubuntu 16.04上启用优化的代码在执行时会生成无限循环:
#include <stdio.h>
void *loop(char *filename){
int counter = 10;
int level = 0;
char *filenames[10];
filenames[0] = filename;
while (counter-- > 0) {
level++;
if (level > 10) {
break;
}
printf("Level %d - MAX_LEVELS %d\n", level, 10);
filenames[level] = filename;
}
return NULL;
}
int main(int argc, char *argv[]) {
loop(argv[0]);
}
Run Code Online (Sandbox Code Playgroud)
编译器版本:
gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
Run Code Online (Sandbox Code Playgroud)
使用的编译命令:
gcc infinite.c -O2 -o infinite
Run Code Online (Sandbox Code Playgroud)
我知道它是由优化标志"-02"引起的,因为没有它就不会发生.我也知道将 …