python-crowd is a python client library to the Atlassian Crowd REST API.
This library may be useful to you if you wish to create an application that authenticates users against Crowd or integrate with Crowd’s SSO.
This project has no official status within Atlassian and is provided as a service to the programming community. I hope that you find it useful.
Docs are built automatically by sphinx. You can build them yourself in the doc directory or access them at <http://aelse.github.com/python-crowd/>.
Some example invocations are provided in the examples directory, and are included in the built documentation.
The unit tests may also be instructive.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
Contents:
Crowd server authentication object.
This is a Crowd authentication class to be configured for a particular application (app_name) to authenticate users against a Crowd server (crowd_url).
This module uses the Crowd JSON API for talking to Crowd.
An application account must be configured in the Crowd server and permitted to authenticate users against one or more user directories prior to using this module.
Please see the Crowd documentation for information about configuring additional applications to talk to Crowd.
Test that application can authenticate to Crowd.
Attempts to authentication the application user against the Crowd server. In order for user authentication to work, an application must be able to authenticate.
Authenticate a user account against the Crowd server.
Attempts to authenticate the user against the Crowd server.
username: The account username.
password: The account password.
None: If authentication failed.
Retrieves a list of group names that have <username> as a direct member.
Retrieves a list of all users that directly or indirectly belong to the given groupname.
Retrieve a list of all group names that have <username> as a direct or indirect member.
Create a session for a user.
Attempts to create a user session on the Crowd server.
username: The account username.
password: The account password.
None: If authentication failed.
Terminates the session token, effectively logging out the user from all crowd-enabled services.
True: If session terminated
None: If session termination failed
Determines if the user exists.
Validate a session token.
Validate a previously acquired session token against the Crowd server. This may be a token provided by a user from a http cookie or by some other means.
token: The session token.
remote: The remote address of the user.
None: If authentication failed.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | import crowd
import os, sys, getpass
app_url = 'http://my.crowd.server:8095/crowd/'
app_user = 'testapp'
app_pass = 'testpass'
# Create the reusable Crowd object
cs = crowd.CrowdServer(app_url, app_user, app_pass)
if len(sys.argv) > 1:
username = sys.argv[1]
else:
username = os.environ['USER']
password = getpass.getpass(prompt='Enter password for %s: ' % username)
success = cs.auth_user(username, password)
if success:
print 'Successfully authenticated.'
else:
print 'Failed to authenticate.'
|
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 | import crowd
import os, sys, getpass
app_url = 'http://my.crowd.server:8095/crowd/'
app_user = 'testapp'
app_pass = 'testpass'
# Create the reusable Crowd object
cs = crowd.CrowdServer(app_url, app_user, app_pass)
if len(sys.argv) > 1:
username = sys.argv[1]
else:
username = os.environ['USER']
password = getpass.getpass(prompt='Enter password for %s: ' % username)
# Create a session. The important bit is the token.
session = cs.get_session(username, password)
if session:
print 'Created a session, token %s' % session['token']
else:
print 'Failed to authenticate.'
sys.exit(1)
# Check that the token is valid (and of course it should be).
success = cs.validate_session(session['token'])
if success:
print 'Authenticated session token.'
else:
print 'Failed to authenticate token.'
|