-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoauth_load.py
49 lines (40 loc) · 1.35 KB
/
oauth_load.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#! /usr/bin/python
# -*- coding: utf-8 -*-
# This is our Brightcove "module" containing both our oAuth procedure and the functions necessary for working with Brightcove's
# Dynamic Ingest API
print "Content-type: application/json\n\n"
import httplib
import urllib
import base64
import json
import requests
# Read the oauth secrets and account ID from our oauth configuration file "brightcove_oauth.txt" located in
# same directory as our Python scripts
def loadSecret():
credsFile = open('brightcove_oauth.txt')
creds = json.load(credsFile)
return creds
# get the oauth 2.0 token
def getAuthToken(creds):
conn = httplib.HTTPSConnection("oauth.brightcove.com")
url = "/v3/access_token"
params = {
"grant_type": "client_credentials"
}
client = creds["client_id"]
client_secret = creds["client_secret"]
authString = base64.encodestring(
'%s:%s' %
(client, client_secret)).replace(
'\n', '')
requestUrl = url + "?" + urllib.urlencode(params)
headersMap = {
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": "Basic " + authString
}
conn.request("POST", requestUrl, headers=headersMap)
response = conn.getresponse()
if response.status == 200:
data = response.read()
result = json.loads(data)
return result["access_token"]