Skip to content

Instantly share code, notes, and snippets.

@Roadmaster
Created April 10, 2019 19:34
Show Gist options
  • Save Roadmaster/ac4434bb98e34b5d3d0bb371d87151c2 to your computer and use it in GitHub Desktop.
Save Roadmaster/ac4434bb98e34b5d3d0bb371d87151c2 to your computer and use it in GitHub Desktop.
calculate oauth signature - for SSO static test validation
#!/usr/bin/env fades
from pprint import pprint
from urllib.parse import urlencode
from oauthlib import oauth1 # fades
# client_key is the openid_identifier from the account
# client_secret is the oauth_secret from the account
# resource_owner_key is the key from the token in account.token_set.create
# resource_owner_secret is the secret from the above
# timestamp and nonce should be the fixed values noted in the existing test
client = oauth1.Client(
client_key='1234567',
client_secret='1234567890',
resource_owner_key='12345678901234567890123456789012345678901234567890',
resource_owner_secret='0987654321',
timestamp='1442966400',
nonce='12345')
# The values of params should be utf8-encoded strings/bytes.
# Here we're using unicode literals explicitly
params = [
('name', u'ñoño ñandú'.encode('utf-8')),
('email', u'[email protected]'.encode('utf-8')),
('name', u'algo más'.encode('utf-8')),
]
base_url = 'http://sso-xenial:8000/error'
# url must contain the query string
url = base_url + "?" + urlencode(params)
uri, headers, body = client.sign(url, http_method='GET', realm=base_url)
# Here are the final headers, oauth_signature SHOULD match
# cOCcOe6F5qLDl43G1uvn1tx9Eig%3D for base_url = sso-trusty
# dLLmmW1bgi%2FWN1oY2kuh%2BSeIXUs%3D for base_url = sso-xenial
pprint(headers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment