OTP Example

{% import json %} {% set user = handler.current_user %} {% if user %}

You are logged in. Here is your user object.

{{ json.dumps(user) }}

Log in as another user via Google, LDAP, Simple or DB.

{% if handler.get_argument('generate-otp', None) %} {% set otp = handler.otp(expire=60) %} {% set url = handler.request.protocol + '://' + handler.request.host + handler.request.path + '?gramex-otp=' + otp %}

Test OTP

Your OTP is {{ otp }}. This will expire in 1 minute.

Open this link {{ url }} in a new browser or private window within 1 minute. You will be logged in as the same user.

When making server-side or AJAX requests, a better way is to use the X-Gramex-OTP: {{ otp }} HTTP header.

{% elif handler.get_argument('gramex-otp', None) %}

User set using OTP

This URL has used up the OTP {{ handler.get_argument('gramex-otp') }}.

Reloading this page will raise a HTTP error. This is a one-time password.

{% else %}

Generate OTP

Click here to generate a new OTP.

{% end %} {% else %}

You are not logged in.

To try this example, log in via Google, LDAP, Simple or DB.

{% end %}