Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过Python使用OAuth访问Sharepoint资源_Python_Sharepoint_Oauth - Fatal编程技术网

通过Python使用OAuth访问Sharepoint资源

通过Python使用OAuth访问Sharepoint资源,python,sharepoint,oauth,Python,Sharepoint,Oauth,我熟悉OAuth,但不熟悉Microsoft的API是如何工作的。他们有很多无组织的文档,真的不能帮助我理解该做什么。我想使用Python脚本访问Sharepoint文件。我想使用客户机id和客户机机密来获取特定sharepoint网站的访问令牌并访问那里的资源。最好的方法是什么?是否有任何官方的microsoft API/文档可以简化此过程 谢谢你的帮助 检查下面的代码。下面的代码: 或者我们可以使用访问SharePoint import cherrypy import jwt import

我熟悉OAuth,但不熟悉Microsoft的API是如何工作的。他们有很多无组织的文档,真的不能帮助我理解该做什么。我想使用Python脚本访问Sharepoint文件。我想使用客户机id和客户机机密来获取特定sharepoint网站的访问令牌并访问那里的资源。最好的方法是什么?是否有任何官方的microsoft API/文档可以简化此过程


谢谢你的帮助

检查下面的代码。下面的代码:

或者我们可以使用访问SharePoint

import cherrypy
import jwt
import urllib.parse, urllib.request
import json

SPSECRET = 'gpYucHkODHOv6JxZJ89Kihl9ncTiTrUCAbOaF1N6uJE='

cherrypy.config.update({'server.socket_port': 3005,
                        'server.ssl_module': 'builtin',
                        'server.ssl_certificate': 'cert.pem',
                        'server.ssl_private_key': 'privkey.pem'})

class GetAccessToken(object):
    def index(self, **kwargs):
        cl = cherrypy.request.body.params
        spapptoken = cl['SPAppToken']
        decodedtoken = jwt.decode(spapptoken, SPSECRET, verify=False)

        url = json.loads(decodedtoken['appctx'])['SecurityTokenServiceUri']
        values = {
            'grant_type': 'refresh_token',
            'client_id': decodedtoken['aud'].split('/')[0],
            'client_secret': SPSECRET,
            'refresh_token': decodedtoken['refreshtoken'],
            'resource': decodedtoken['appctxsender'].split('@')[0] + '/' + decodedtoken['aud'].split('/')[1].split('@')[0] + '@' + decodedtoken['appctxsender'].split('@')[1]
        }
        data = urllib.parse.urlencode(values)
        binarydata = data.encode('ascii')
        req = urllib.request.Request(url, binarydata)
        response = urllib.request.urlopen(req)
        page = response.read()

        return repr(page)

    index.exposed = True

cherrypy.quickstart(GetAccessToken())