Skip to content

Remove REPL artifacts from WSSE documentation #1453

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 63 additions & 53 deletions docs/wsse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ WS-Security incorporates security features in the header of a SOAP message.

UsernameToken
-------------
The UsernameToken supports both the passwordText and passwordDigest methods::
The UsernameToken supports both the passwordText and passwordDigest methods:

>>> from zeep import Client
>>> from zeep.wsse.username import UsernameToken
>>> client = Client(
... 'http://www.webservicex.net/ConvertSpeed.asmx?WSDL',
... wsse=UsernameToken('username', 'password'))
.. code-block:: python

from zeep import Client
from zeep.wsse.username import UsernameToken
client = Client(
'http://www.webservicex.net/ConvertSpeed.asmx?WSDL',
wsse=UsernameToken('username', 'password'))

To use the passwordDigest method you need to supply `use_digest=True` to the
`UsernameToken` class.
Expand All @@ -26,28 +28,32 @@ platform.

To append the security token as `BinarySecurityToken`, you can use wsse.BinarySignature() plugin.

Example usage A::

>>> from zeep import Client
>>> from zeep.wsse.signature import Signature
>>> client = Client(
... 'http://www.webservicex.net/ConvertSpeed.asmx?WSDL',
... wsse=Signature(
... private_key_filename, public_key_filename,
... optional_password))

Example usage B::

>>> from zeep import Client
>>> from zeep.wsse.signature import Signature
>>> from zeep.transports import Transport
>>> from requests import Session
>>> session = Session()
>>> session.cert = '/path/to/ssl.pem'
>>> transport = Transport(session=session)
>>> client = Client(
... 'http://www.webservicex.net/ConvertSpeed.asmx?WSDL',
... transport=transport)
Example usage A:

.. code-block:: python

from zeep import Client
from zeep.wsse.signature import Signature
client = Client(
'http://www.webservicex.net/ConvertSpeed.asmx?WSDL',
wsse=Signature(
private_key_filename, public_key_filename,
optional_password))

Example usage B:

.. code-block:: python

from zeep import Client
from zeep.wsse.signature import Signature
from zeep.transports import Transport
from requests import Session
session = Session()
session.cert = '/path/to/ssl.pem'
transport = Transport(session=session)
client = Client(
'http://www.webservicex.net/ConvertSpeed.asmx?WSDL',
transport=transport)

.. _xmlsec: https://pypi.python.org/pypi/xmlsec
.. _README: https://github.com/mehcode/python-xmlsec
Expand All @@ -59,15 +65,17 @@ UsernameToken and Signature together
To use UsernameToken and Signature together, then you can pass both together
to the client in a list

>>> from zeep import Client
>>> from zeep.wsse.username import UsernameToken
>>> from zeep.wsse.signature import Signature
>>> user_name_token = UsernameToken('username', 'password')
>>> signature = Signature(private_key_filename, public_key_filename,
... optional_password)
>>> client = Client(
... 'http://www.webservicex.net/ConvertSpeed.asmx?WSDL',
... wsse=[user_name_token, signature])
.. code-block:: python

from zeep import Client
from zeep.wsse.username import UsernameToken
from zeep.wsse.signature import Signature
user_name_token = UsernameToken('username', 'password')
signature = Signature(private_key_filename, public_key_filename,
optional_password)
client = Client(
'http://www.webservicex.net/ConvertSpeed.asmx?WSDL',
wsse=[user_name_token, signature])


UsernameToken with Timestamp token
Expand All @@ -77,19 +85,21 @@ To use UsernameToken with Timestamp token, first you need an instance of `WSU.Ti
containing `WSU.Created()` and `WSU.Expired()` elements, finally pass it as `timestamp_token` keyword argument
to `UsernameToken()`.

>>> import datetime
>>> from zeep import Client
>>> from zeep.wsse.username import UsernameToken
>>> from zeep.wsse.utils import WSU
>>> timestamp_token = WSU.Timestamp()
>>> today_datetime = datetime.datetime.today()
>>> expires_datetime = today_datetime + datetime.timedelta(minutes=10)
>>> timestamp_elements = [
... WSU.Created(today_datetime.strftime("%Y-%m-%dT%H:%M:%SZ")),
... WSU.Expires(expires_datetime.strftime("%Y-%m-%dT%H:%M:%SZ"))
...]
>>> timestamp_token.extend(timestamp_elements)
>>> user_name_token = UsernameToken('username', 'password', timestamp_token=timestamp_token)
>>> client = Client(
... 'http://www.webservicex.net/ConvertSpeed.asmx?WSDL', wsse=user_name_token
...)
.. code-block:: python

import datetime
from zeep import Client
from zeep.wsse.username import UsernameToken
from zeep.wsse.utils import WSU
timestamp_token = WSU.Timestamp()
today_datetime = datetime.datetime.today()
expires_datetime = today_datetime + datetime.timedelta(minutes=10)
timestamp_elements = [
WSU.Created(today_datetime.strftime("%Y-%m-%dT%H:%M:%SZ")),
WSU.Expires(expires_datetime.strftime("%Y-%m-%dT%H:%M:%SZ"))
]
timestamp_token.extend(timestamp_elements)
user_name_token = UsernameToken('username', 'password', timestamp_token=timestamp_token)
client = Client(
'http://www.webservicex.net/ConvertSpeed.asmx?WSDL', wsse=user_name_token
)