-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdemo.py
More file actions
42 lines (35 loc) · 1.76 KB
/
demo.py
File metadata and controls
42 lines (35 loc) · 1.76 KB
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
#
# A simple script to demostrate connecting to Blackboard Learn 9.1
# Web Services using the Python Suds SOAP client library.
#
# Use at your own risk.
#
# Written by Chris Conover on July 29, 2010
# Requires Suds 0.4 for plugin support
# https://fedorahosted.org/suds/
from suds.client import Client
from suds.plugin import MessagePlugin
from suds.wsse import Timestamp, UsernameToken, Security
# The base web service URL of your server
WS_BASE_URL = 'https://learndev.cms.ucf.edu/webapps/ws/services/' # Something link https://your.institution.edu/webapps/ws/services/
# Suds does not provide the "type" attribute on the Password tag
# of the UsernameToken in the WS-Security SOAP headers. Create
# a plugin which adds it at send time.
class Learn9Plugin(MessagePlugin):
def marshalled(self, context):
password = context.envelope.childAtPath('Header/Security/UsernameToken/Password')
password.set('Type', 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText')
# WS-Security Headers. Timestamp token MUST come before UsernameToken
security = Security()
security.tokens.append(Timestamp())
# Set initial WS-Security user ID and password.
# Password will be updated with the result of the `initialize` operation.
security.tokens.append(UsernameToken('session', 'nosession'))
client = Client(
WS_BASE_URL + 'Context.WS?wsdl',
location = WS_BASE_URL + 'Context.WS', # Learn 9.1 WSDL misreports service endpoints so set it manually
autoblend = True, # Learn 9.1 WSDLs use nested imports
wsse = security, # Add WS-Security tokens
plugins = [Learn9Plugin()]) # Add WS-Security/UsernameToken/Password Type fix
session_password = client.service.initialize()
client.options.wsse.tokens[1].password = session_password