• File: open_id.cpython-37.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/opt/alt/python37/lib/python3.7/site-packages/paste/auth/__pycache__/open_id.cpython-37.pyc
  • Date Modified: 12/01/2019 7:09 PM
  • File size: 10.78 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit
B

aN?@sdZdgZddlZddlZddlZddlZddlmZddZddl	m
Z
ddlmZdd	l
mZGd
ddeZeZdd
dZdS)a
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.
AuthOpenIDHandlerN)httpexceptionscCst|d}d|fS)Nz"%s")cgiescape)sqsr	C/opt/alt/python37/lib/python3.7/site-packages/paste/auth/open_id.py	quoteattrAsr)	filestore)consumer)
appendArgsc@sleZdZdZdddZddZd	d
ZddZd
dZddZ	ddZ
ddZdddZddZ
ddZdS) rzq
    This middleware implements OpenID Consumer behavior to authenticate a
    URL against an OpenID Server.
    /oidNFcCs>t|}t||_||_||_||_||_||_	||_
dS)a
        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)rZFileOpenIDStorer
ZOpenIDConsumeroidconsumerappauth_prefixdata_store_pathlogin_redirect	catch_401url_to_username)selfrrrrrrstorer	r	r
__init__Us
zAuthOpenIDHandler.__init__cCs|d|jrt||gd}tjj|ddd|d<t|jd|d}t||d<ttj	||d<|dd	}|d
ks|s|
|S|dkr||S|dkr||S|
|Sn|jr|||S|||SdS)
N	PATH_INFO)environstartbodyF)with_path_infowith_query_stringbase_url
parsed_uriquery/z/verifyz/process)
startswithrdictpasterequest
construct_urlresuburlparseZparse_querystringrender	do_verify
do_process	not_foundrcatch_401_app_callr)rrstart_responser)pathr	r	r
__call__ys$



zAuthOpenIDHandler.__call__c	svgdfdd	}|||}rnzt|Wdt|drD|Xtjj|ddd}t|}|	|S|SdS)zV
        Call the application, and redirect if the app returns a 401 response
        Ncs:t|dddkr*ddd}|S|||SdS)NricSsdS)Nr	)vr	r	r
dummy_writersz^AuthOpenIDHandler.catch_401_app_call.<locals>.replacement_start_response.<locals>.dummy_writer)intsplitappend)statusheadersexc_infor7)r3was_401r	r
replacement_start_responses

zHAuthOpenIDHandler.catch_401_app_call.<locals>.replacement_start_responsecloseF)rr)N)
rlisthasattrr@r(r)r*rZHTTPTemporaryRedirectZwsgi_application)rrr3r?Zapp_iterZ	redir_urlexcr	)r3r>r
r2s




z$AuthOpenIDHandler.catch_401_app_callc
Cs|dd}|s$|j|dd|dS|j}||\}}|tjtjgkr~|tjkrXd}nd}|t|f}|j||d|dS|tj	kr|j
|d|jd	}|j|||d
d}	|
||	Sdstd
dS)zDProcess the form submission, initating OpenID verification.
        r#
openid_urlz Enter an identity URL to verify.error)	css_class
form_contentszFailed to retrieve <q>%s</q>z.Could not find OpenID information in <q>%s</q>process)tokenr )Z
trust_rootFzNot reachedN)getr.rZ	beginAuthr
ZHTTP_FAILUREZPARSE_ERRORrrSUCCESS	build_urlrIZconstructRedirectredirectAssertionError)
rr)rDrr;infofmtmessageZ	return_toredirect_urlr	r	r
r/s$


zAuthOpenIDHandler.do_verifycCs|j}|ddd}|||d\}}d}d}|tjkrZ|rZ|}d}|t|f}	n|tjkrd}|r|}|jr||d|}
n|}
d	|dkr|dd	|
|j	sd
}|t|f}	q||dd<|j	|dd<|
|d|d
Sqd}	nd}	|||	||S)z4Handle the redirect from the OpenID server.
        r#rIr!rENzVerification of %s failed.alertrzpaste.auth_tkt.set_userzIf you had supplied a login redirect path, you would have been redirected there.  You have successfully verified %s as your identity.zpaste.auth.open_idrrzVerification cancelledzVerification failed.)rrJZcompleteAuthr
FAILURErrrKrrrr.)rr)rrIr;rOrFrDrPrQusernamer	r	r
r0s6
zAuthOpenIDHandler.do_processcKs$t|d|jd|}t||S)z[Build a URL relative to the server base_url, with the given
        query parameters added.r r%)r-urljoinrr)rr)actionr#baser	r	r
rL!szAuthOpenIDHandler.build_urlcCs$dd|fg}|dd|d|gS)z9Send a redirect response to the given URL to the browser.)zContent-typez
text/plainZLocationrz302 REDIRECTzRedirecting to %sr	)rr)rRresponse_headersr	r	r
rM's
zAuthOpenIDHandler.redirectcCs4d}||df}|dd}|j||d|ddS)z3Render a page with a 404 return code and a message.z5The path <q>%s</q> was not understood by this server.r"r#rDrEz
404 Not Found)r;)rJr.)rr)rPmsgrDr	r	r
r1.szAuthOpenIDHandler.not_foundrS200 OKPython OpenID ConsumercCsldg}|dt||||||rX|dd|f|d||dd||||dS)zRender a page.)zContent-typez	text/htmlrrz<div class='%s'>z</div>)strpage_headerr:page_footer)rr)rQrFrGr;titlerYr	r	r
r.5szAuthOpenIDHandler.rendercCs|dd||fdS)zRender the page headerraT<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)r:)rr)r`r	r	r
r^Cs(zAuthOpenIDHandler.page_headercCs2|sd}|ddt||dt|fdS)zRender the page footerr!rz    <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>
ZverifyN)r:rrL)rr)rGr	r	r
r_os
zAuthOpenIDHandler.page_footer)rNFN)NrSNr[r\)__name__
__module____qualname____doc__rr5r2r/r0rLrMr1r.r^r_r	r	r	r
rOs
"3?

,/oidFc	
Cs|ddlm}	ddlm}
|	|}|r8t|tr8|
|}|	|}t||||||pRdd}|rxddlm	}|j
|||d}|S)Nr)asbool)
import_string)rrrrr)auth_tkt)Zlogout_path)Zpaste.deploy.convertersrfZ
paste.utilrg
isinstance
basestringZeval_importrZ
paste.authrhZmake_auth_tkt_middleware)
rZglobal_confrrrrrZapply_auth_tktZauth_tkt_logout_pathrfrgZnew_apprhr	r	r
make_open_id_middlewares
rk)reNFNFN)rd__all__rr-r+Z
paste.requestr(rrZopenid.storerZopenid.consumerr
Zopenid.oidutilrobjectrZ
middlewarerkr	r	r	r
<module>6s(
4