python 3 登录azureAD并调用azure graph api
来源:互联网 发布:淘宝老客户营销短信 编辑:程序博客网 时间:2024/04/30 06:13
parameters.json :
{ "resource": "https://graph.microsoft.com/", "tenant" : "{your_directoryId}", "authorityHostUrl" : "https://login.microsoftonline.com", "clientid" : "{your_app_id}", "username" : "{username}", "password" : "{password}" }
test.py:
import jsonimport loggingimport osimport sysimport adalparameters_file = (sys.argv[1] if len(sys.argv) == 2 else os.environ.get('ADAL_SAMPLE_PARAMETERS_FILE'))if parameters_file: with open(parameters_file, 'r') as f: parameters = f.read() sample_parameters = json.loads(parameters)else: raise ValueError('Please provide parameter file with account information.')authority_url = (sample_parameters['authorityHostUrl'] + '/' + sample_parameters['tenant'])GRAPH_RESOURCE = '00000002-0000-0000-c000-000000000000'RESOURCE = sample_parameters.get('resource', GRAPH_RESOURCE)#uncomment for verbose log#turn_on_logging()context = adal.AuthenticationContext( authority_url, validate_authority=sample_parameters['tenant'] != 'adfs', api_version=None)######################################################### below is the token based on username/password########################################################tokenRet = context.acquire_token_with_username_password( RESOURCE, sample_parameters['username'], sample_parameters['password'], sample_parameters['clientid'])token = tokenRet['accessToken']print('Here is the access token get by username/password')print(json.dumps(token, indent=2))######################################################### below code to get access token based on refresh token#########################################################refresh_token = tokenRet['refreshToken']retToken = context.acquire_token_with_refresh_token( refresh_token, sample_parameters['clientid'], RESOURCE)token = retToken['accessToken']print('Here is the token acquired from the refreshing token')print(json.dumps(token, indent=2))############################################################ below is the user profile information get from azure graph api# for more information:# https://developer.microsoft.com/en-us/graph/graph-explorer############################################################import urllib2req = urllib2.Request('https://graph.microsoft.com/v1.0/users')req.add_header('Authorization', 'Bearer '+token)resp = urllib2.urlopen(req)content = resp.read()print('below is the user profile info:')print(content)
阅读全文
1 0
- python 3 登录azureAD并调用azure graph api
- asp.net Webapi登录azureAD并调用azure graph api
- 使用python调用azure api步骤文档
- Python使用API登录Ckan并下载资源
- Java 调用 Azure HTTPS API 证书问题
- 调用graph api上传图片到facebook
- Microsoft Azure AD 用户搜索分页api调用
- 【3】python有道调用API进行翻译
- Python 调用百度API
- python百度api调用
- python模拟登录新浪微博自动获得调用新浪api所需的code
- python模拟登录新浪微博自动获得调用新浪api所需的code
- Python调用豆瓣API抓取top250电影并存储进数据库
- 利用python调用elasticsearch-api来分析数据并作图进行日报邮件发送
- C#调用Windows API实现自动登录
- C#调用Windows API实现自动登录
- C#调用Windows API实现自动登录
- C#调用Windows API实现自动登录
- 设计模式C++版:第十九式解释器模式
- redis安装
- 喷水装置(二) 区间长度贪心
- Jboss与Tomcat的区别
- json转换成excel在线js小工具分享
- python 3 登录azureAD并调用azure graph api
- (6)中文乱码处理
- LeetCode 413. Arithmetic Slices
- python字符串
- LA 4670 Dominating Patterns——AC自动机
- ubuntu 请尝试不指明软件包的名字来运行“apt-get -f install”(也可以指定一个解决办法)。
- Android客户端与服务器端的json数据交互(很详细)
- Unity 3D 官方文档 UGUI总览 IMGUI OnGUI Editor脚本初窥2
- WebView的简单使用,JS的调用