Search…
Overview
Passage provides backend libraries to simplify the entire process of user management. There are two main use cases for a backend library:
  1. 1.
    Authenticating Requests
  2. 2.
    Managing Passage Users

Authenticating Requests

Passage serves as your identity provider (IDP) by storing all of your app's users and authentication material. With a Passage Element, users obtain an authentication token from Passage before making subsequent requests to your web server. When a user makes an authenticated request, it is your web server's responsibility to ensure that the request is properly authenticated. Passage backend libraries make it easy. Examples of using a Passage backend library to authenticate an HTTP request are shown below:
Go
Node.js
Python (Flask)
1
import (
2
"net/http"
3
​
4
"github.com/passageidentity/passage-go"
5
)
6
​
7
func exampleHandler(w http.ResponseWriter, r *http.Request) {
8
​
9
// Authenticate this request using the Passage SDK:
10
psg, _ := passage.New("<PASSAGE_APP_ID>", nil)
11
_, err := psg.AuthenticateRequest(r)
12
if err != nil {
13
// 🚨 Authentication failed!
14
w.WriteHeader(http.StatusUnauthorized)
15
return
16
}
17
​
18
// βœ… Authentication successful. Proceed...
19
​
20
}
Copied!
1
import Passage from "@passageidentity/passage-node";
2
​
3
// Passage requires an App ID and, optionally, an API Key
4
const passageConfig = {
5
appID: process.env.PASSAGE_APP_ID,
6
apiKey: process.env.PASSAGE_API_KEY,
7
};
8
​
9
// Authentication using Passage class instance
10
let passage = new Passage(passageConfig);
11
app.get("/authenticatedRoute", async(req, res) => {
12
try {
13
// Authenticate request using Passage
14
let userID = await passage.authenticateRequest(req, res);
15
if (userID) {
16
// User is authenticated
17
let userData = await passage.user.get(userID);
18
console.log(userData);
19
}
20
} catch (e) {
21
// Authentication failed
22
console.log(e);
23
res.send("Authentication failed!");
24
}
25
});
Copied!
1
from passageidentity import Passage
2
import os
3
​
4
PASSAGE_APP_ID = os.environ.get("PASSAGE_APP_ID")
5
​
6
class AuthenticationMiddleware(object):
7
def __init__(self, app):
8
self.app = app
9
​
10
def __call__(self, environ, start_response):
11
request = Request(environ)
12
psg = Passage(PASSAGE_APP_ID)
13
try:
14
user = psg.authenticateRequest(request)
15
except:
16
ret = Response(u'Authorization failed', mimetype='text/plain', status=401)
17
return ret(environ, start_response)
18
environ['user'] = user
19
return self.app(environ, start_response)
Copied!

Managing Passage Users

Passage backend libraries can be used to manage and query Passage users. You can use these functions to get information about a user, update a user's email, and activate or deactivate a user. Please see the specific SDK reference pages to learn about the language-specific interfaces for user management functionality.
In addition to your App ID, managing users requires authentication to Passage in the form of an API key. This ensure that only your application has access to information about your users. You can generate and manage your API keys in the App Settings in the Passage Console. Go there now.​

Libraries

Last modified 30d ago