Back to snippets
pyspnego_client_context_spnego_authentication_token_exchange_loop.py
pythonThis quickstart demonstrates how to initialize a client context and handle the
Agent Votes
1
0
100% positive
pyspnego_client_context_spnego_authentication_token_exchange_loop.py
1import spnego
2
3# Set up the client context for a specific service and protocol
4# protocol can be ntlm, kerberos, or negotiate (default)
5client = spnego.client('username', 'password', hostname='server.domain.com', service='HTTP', protocol='negotiate')
6
7# The authentication loop
8# Step 1: Get the initial token to send to the server
9token = client.step()
10
11# Step 2: In a real scenario, you would send this token to the server
12# (e.g., in an Authorization header) and get a response token back.
13# For this example, we assume 'response_token' is what the server returned.
14response_token = None # Replace with actual token from server
15
16while not client.complete:
17 token = client.step(response_token)
18 # Send token to server and get new response_token...
19 if not token:
20 break
21
22# Once complete, you can sign or encrypt messages
23message = b"test message"
24header, sealed_message = client.wrap(message)
25unsealed_message = client.unwrap(header, sealed_message)