How to get the Domino username of an App viewer
Overview
Domino passes the username of a user accessing your Domino App in an HTTP header named domino-username.
If your App framework gives you access to the HTTP headers of the active request, you can retrieve the username for use by your App code. If you allow users who are not logged in to Domino to view your Apps, for their requests to the App the value of the domino-username header will be "Anonymous."
Prerequisite
Example
Consider this simple Flask example where you have the following files in your project.
An app.sh script that starts your app code listening on the correct port.
#!/usr/bin/env bash export LC_ALL=C.UTF-8 export LANG=C.UTF-8 export FLASK_APP=app.py export FLASK_DEBUG=1 python -m flask run --host=0.0.0.0 --port=8888
A simple app.py file that renders a template named index.html. Note that this app imports request from flask, which gives you access to the headers of the active HTTP request.
import flask from flask import request, redirect, url_for class ReverseProxied(object): def __init__(self, app): self.app = app def __call__(self, environ, start_response): script_name = environ.get('HTTP_X_SCRIPT_NAME', '') if script_name: environ['SCRIPT_NAME'] = script_name path_info = environ['PATH_INFO'] if path_info.startswith(script_name): environ['PATH_INFO'] = path_info[len(script_name):] return self.app(environ, start_response) app = flask.Flask(__name__) app.wsgi_app = ReverseProxied(app.wsgi_app) # Homepage which uses a template file @app.route('/') def index_page(): return flask.render_template("index.html")
A template file at templates/index.html that fetches the domino-username header from the requests object and renders it.
<!DOCTYPE html> <html> <body> <h1>Your username is {{ request.headers.get("domino-username") }}</h1> </body> </html>
If you host this App in Domino and open it, you'll see something like the following, where the username shown will match the username of the user viewing the App.
Comments
0 comments
Please sign in to leave a comment.