%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /proc/self/root/opt/alt/python27/lib/python2.7/site-packages/paste/auth/
Upload File :
Create Path :
Current File : //proc/self/root/opt/alt/python27/lib/python2.7/site-packages/paste/auth/open_id.pyo

�
a�Nc@s�dZdgZddlZddlZddlZddlZddlmZd�Zddl	m
Z
ddlmZddl
mZdefd	��YZeZd
eeeeed�ZdS(s�
OpenID Authentication (Consumer)

OpenID is a distributed authentication system for single sign-on originally
developed at/for LiveJournal.com.

    http://openid.net/

URL. You can have multiple identities in the same way you can have multiple
URLs. All OpenID does is provide a way to prove that you own a URL (identity).
And it does this without passing around your password, your email address, or
anything you don't want it to. There's no profile exchange component at all:
your profiile is your identity URL, but recipients of your identity can then
learn more about you from any public, semantically interesting documents
linked thereunder (FOAF, RSS, Atom, vCARD, etc.).

``Note``: paste.auth.openid requires installation of the Python-OpenID
libraries::

    http://www.openidenabled.com/

This module is based highly off the consumer.py that Python OpenID comes with.

Using the OpenID Middleware
===========================

Using the OpenID middleware is fairly easy, the most minimal example using the
basic login form thats included::

    # Add to your wsgi app creation
    from paste.auth import open_id

    wsgi_app = open_id.middleware(wsgi_app, '/somewhere/to/store/openid/data')

You will now have the OpenID form available at /oid on your site. Logging in will
verify that the login worked.

A more complete login should involve having the OpenID middleware load your own
login page after verifying the OpenID URL so that you can retain the login
information in your webapp (session, cookies, etc.)::

    wsgi_app = open_id.middleware(wsgi_app, '/somewhere/to/store/openid/data',
                                  login_redirect='/your/login/code')

Your login code should then be configured to retrieve 'paste.auth.open_id' for
the users OpenID URL. If this key does not exist, the user has not logged in.

Once the login is retrieved, it should be saved in your webapp, and the user
should be redirected to wherever they would normally go after a successful
login.
tAuthOpenIDHandleri����N(thttpexceptionscCstj|d�}d|fS(Nis"%s"(tcgitescape(tstqs((sC/opt/alt/python27/lib/python2.7/site-packages/paste/auth/open_id.pyt	quoteattrAs(t	filestore(tconsumer(t
appendArgscBs�eZdZddedd�Zd�Zd�Zd�Zd�Z	d�Z
d�Zd	�Zdd
dddd
�Z
d�Zd�ZRS(sq
    This middleware implements OpenID Consumer behavior to authenticate a
    URL against an OpenID Server.
    s/oidcCs[tj|�}tj|�|_||_||_||_||_||_	||_
dS(s�
        Initialize the OpenID middleware

        ``app``
            Your WSGI app to call
            
        ``data_store_path``
            Directory to store crypto data in for use with OpenID servers.
            
        ``auth_prefix``
            Location for authentication process/verification
            
        ``login_redirect``
            Location to load after successful process of login
            
        ``catch_401``
            If true, then any 401 responses will turn into open ID login
            requirements.
            
        ``url_to_username``
            A function called like ``url_to_username(environ, url)``, which should
            return a string username.  If not given, the URL will be the username.
        N(RtFileOpenIDStoreRtOpenIDConsumertoidconsumertapptauth_prefixtdata_store_pathtlogin_redirectt	catch_401turl_to_username(tselfR
RRRRRtstore((sC/opt/alt/python27/lib/python2.7/site-packages/paste/auth/open_id.pyt__init__Us					cCs;|dj|j�rtd|d|dg�}tjj|dtdt�|d<tj|jd|d�}t	j	|�|d	<ttjj
|��|d
<|d	d}|dks�|r�|j|�S|d
kr�|j|�S|dkr�|j
|�S|j|�Sn)|jr'|j||�S|j||�SdS(Nt	PATH_INFOtenvirontstarttbodytwith_path_infotwith_query_stringtbase_urltt
parsed_uritqueryit/s/verifys/process(t
startswithRtdicttpastetrequestt
construct_urltFalsetretsubturlparsetparse_querystringtrendert	do_verifyt
do_processt	not_foundRtcatch_401_app_callR
(RRtstart_responseR$tpath((sC/opt/alt/python27/lib/python2.7/site-packages/paste/auth/open_id.pyt__call__ys$



	cs�g�d��fd�}|j||�}�r�zt|�Wdt|d�r`|j�nXtjj|dtdt�}t	j
|�}|j|��S|SdS(sV
        Call the application, and redirect if the app returns a 401 response
        csLt|jdd��dkr8�jd�d�}|S�|||�SdS(Nii�cSsdS(N((tv((sC/opt/alt/python27/lib/python2.7/site-packages/paste/auth/open_id.pytdummy_writer�s(tinttsplittNonetappend(tstatustheaderstexc_infoR4(R0twas_401(sC/opt/alt/python27/lib/python2.7/site-packages/paste/auth/open_id.pytreplacement_start_response�s

	NtcloseRR(R7R
tlistthasattrR>R#R$R%R&RtHTTPTemporaryRedirecttwsgi_application(RRR0R=tapp_itert	redir_urltexc((R0R<sC/opt/alt/python27/lib/python2.7/site-packages/paste/auth/open_id.pyR/�s
	c
Cs|djd�}|s5|j|dddd|�S|j}|j|�\}}|tjtjgkr�|tjkr�d}nd}|tj|�f}|j||ddd|�S|tj	kr|j
|d	d
|j�}|j||d|d�}	|j
||	�Sd
S(sDProcess the form submission, initating OpenID verification.
        Rt
openid_urls Enter an identity URL to verify.t	css_classterrort
form_contentssFailed to retrieve <q>%s</q>s.Could not find OpenID information in <q>%s</q>tprocessttokent
trust_rootRN(tgetR+Rt	beginAuthRtHTTP_FAILUREtPARSE_ERRORRRtSUCCESSt	build_urlRKtconstructRedirecttredirect(
RR$RFRR9tinfotfmttmessaget	return_totredirect_url((sC/opt/alt/python27/lib/python2.7/site-packages/paste/auth/open_id.pyR,�s$
		cCsv|j}|djdd�}|j||d�\}}d}d}|tjkr�|r�|}d}|tj|�f}	n�|tjkrZd}|rQ|}|j	r�|j	|d|�}
n|}
d|dkr�|dd|
�n|j
sd	}|tj|�f}	qW||dd
<|j
|dd<|j|d|d�Sq`d
}	nd}	|j||	||�S(s4Handle the redirect from the OpenID server.
        RRKRRHsVerification of %s failed.talertRspaste.auth_tkt.set_users�If you had supplied a login redirect path, you would have been redirected there.  You have successfully verified %s as your identity.spaste.auth.open_idRRsVerification cancelledsVerification failed.N(
RRMtcompleteAuthR7RtFAILURERRRQRRR
R+(RR$RRKR9RURGRFRVRWtusername((sC/opt/alt/python27/lib/python2.7/site-packages/paste/auth/open_id.pyR-�s6				cKs.tj|d|jd|�}t||�S(s[Build a URL relative to the server base_url, with the given
        query parameters added.RR (R)turljoinRR	(RR$tactionRtbase((sC/opt/alt/python27/lib/python2.7/site-packages/paste/auth/open_id.pyRR!s!cCs.dd|fg}|dd|�d|gS(s9Send a redirect response to the given URL to the browser.sContent-types
text/plaintLocationRs302 REDIRECTsRedirecting to %s(sContent-types
text/plain((RR$RYtresponse_headers((sC/opt/alt/python27/lib/python2.7/site-packages/paste/auth/open_id.pyRT'scCsFd}||df}|djd�}|j||d|dd�S(s3Render a page with a 404 return code and a message.s5The path <q>%s</q> was not understood by this server.RRRFRHR9s
404 Not Found(RMR+(RR$RVtmsgRF((sC/opt/alt/python27/lib/python2.7/site-packages/paste/auth/open_id.pyR..sRZs200 OKsPython OpenID ConsumercCs�dg}|dt|�|�|j||�|rs|djd|f�|dj|�|djd�n|j||�|dS(sRender a page.sContent-types	text/htmlRRs<div class='%s'>s</div>(sContent-types	text/html(tstrtpage_headerR8tpage_footer(RR$RWRGRIR9ttitleRb((sC/opt/alt/python27/lib/python2.7/site-packages/paste/auth/open_id.pyR+5s	cCs|djd||f�dS(sRender the page headerRsT<html>
  <head><title>%s</title></head>
  <style type="text/css">
      * {
        font-family: verdana,sans-serif;
      }
      body {
        width: 50em;
        margin: 1em;
      }
      div {
        padding: .5em;
      }
      table {
        margin: none;
        padding: none;
      }
      .alert {
        border: 1px solid #e7dc2b;
        background: #fff888;
      }
      .error {
        border: 1px solid #ff0000;
        background: #ffaaaa;
      }
      #verify-form {
        border: 1px solid #777777;
        background: #dddddd;
        margin-top: 1em;
        padding-bottom: 0em;
      }
  </style>
  <body>
    <h1>%s</h1>
    <p>
      This example consumer uses the <a
      href="http://openid.schtuff.com/">Python OpenID</a> library. It
      just verifies that the URL that you enter is your identity URL.
    </p>
N(R8(RR$Rg((sC/opt/alt/python27/lib/python2.7/site-packages/paste/auth/open_id.pyReCs
(cCsF|sd}n|djdt|j|d��t|�f�dS(sRender the page footerRRs�    <div id="verify-form">
      <form method="get" action=%s>
        Identity&nbsp;URL:
        <input type="text" name="openid_url" value=%s />
        <input type="submit" value="Verify" />
      </form>
    </div>
  </body>
</html>
tverifyN(R8RRR(RR$RI((sC/opt/alt/python27/lib/python2.7/site-packages/paste/auth/open_id.pyRfos	

N(t__name__t
__module__t__doc__R7R&RR2R/R,R-RRRTR.R+ReRf(((sC/opt/alt/python27/lib/python2.7/site-packages/paste/auth/open_id.pyROs"			3	?				
	,s/oidc	
Cs�ddlm}	ddlm}
|	|�}|rSt|t�rS|
j|�}n|	|�}t|d|d|d|d|d|p�d�}|r�dd	l	m
}|j||d
|�}n|S(Ni����(tasbool(t
import_stringRRRRR(tauth_tkttlogout_path(tpaste.deploy.convertersRlt
paste.utilRmt
isinstancet
basestringteval_importRR7t
paste.authRntmake_auth_tkt_middleware(
R
tglobal_confRRRRRtapply_auth_tkttauth_tkt_logout_pathRlRmtnew_appRn((sC/opt/alt/python27/lib/python2.7/site-packages/paste/auth/open_id.pytmake_open_id_middleware�s(Rkt__all__RR)R't
paste.requestR#RRtopenid.storeRtopenid.consumerRtopenid.oidutilR	tobjectRt
middlewareR7R&R{(((sC/opt/alt/python27/lib/python2.7/site-packages/paste/auth/open_id.pyt<module>6s&		
�3

Zerion Mini Shell 1.0