1.1.8 • Published 1 month ago

passport-zitadel v1.1.8

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
1 month ago

Passport for ZITADEL

This package contains passport js strategies for ZITADEL (v2).

As a prerequisite, similar to Google OAuth, you need to create a project and an application in ZITADEL.

Create ZITADEL instance and requirements

Head over to zitadel.cloud and login or create a new account in the customer portal of ZITADEL. Then, you can create a new instance (either free or "pay as you go"). In this new instance, you can create a new project and inside it a new application.

Strategies

This section describes the provided strategies in this package. It is subject to change in the future if more and more strategies are needed.

ZITADEL API Introspection

First and foremost, the introspection strategy allows APIs to verify and validate an access token.

The strategy is based on the OAuth 2.0 Token Introspection (RFC 7662) and checks if the provided access token (HTTP Authorization header) is valid and active.

The strategy requires an "API Project" in ZITADEL, which is either configured with "Basic" or "JWT Profile" as authentication method. Both variants are supported in the strategy. The JWT profile variant is recommended.

The diagram below explains the introspection workflow:

sequenceDiagram
    participant User
    participant ZITADEL
    participant API

    User->>+ZITADEL: Obtain access token
    ZITADEL-->>-User: Access token
    User->>+API: Call API with access token
    API->>+ZITADEL: OAuth Introspection
    ZITADEL-->>-API: Introspection result

    alt is valid and active
        API-->>User: Return HTTP 20x with data
    else is invalid or inactive
        API-->>User: Return HTTP 401/403
    end

    deactivate API

Example JWT Profile

Note: To get the JWT profile json file, you can create a valid application key in the API application in ZITADEL and download it.

import express from 'express';
import path from 'path';
import passport from 'passport';
import { ZitadelIntrospectionStrategy } from 'passport-zitadel';

const app = express();
const port = 8080;

// Register the strategy with the correct configuration.
passport.use(
  new ZitadelIntrospectionStrategy({
    authority: 'https://YOUR_ZITADEL_INSTANCE_NAME.zitadel.cloud',
    authorization: {
      type: 'jwt-profile',
      profile: {
        type: 'application',
        keyId: 'key id',
        key: 'private rsa key',
        appId: 'app id',
        clientId: 'client id',
      },
    },
  })
);

app.use(passport.initialize());

app.use(passport.authenticate('zitadel-introspection', { session: false }));
app.get('/', (req, res) => {
  res.send('Hello World!');
});

app.listen(port, () => {
  console.log(`server started at http://localhost:${port}`);
});

Example Basic

import express from 'express';
import path from 'path';
import passport from 'passport';
import { ZitadelIntrospectionStrategy } from 'passport-zitadel';

const app = express();
const port = 8080;

// Register the strategy with the correct configuration.
passport.use(
  new ZitadelIntrospectionStrategy({
    authority: 'https://YOUR_ZITADEL_INSTANCE_NAME.zitadel.cloud',
    authorization: {
      type: 'basic',
      clientId: 'CLIENT ID',
      clientSecret: 'CLIENT SECRET',
    },
  })
);

app.use(passport.initialize());

app.use(passport.authenticate('zitadel-introspection', { session: false }));
app.get('/', (req, res) => {
  res.send('Hello World!');
});

app.listen(port, () => {
  console.log(`server started at http://localhost:${port}`);
});
1.1.8

1 month ago

1.1.7

2 months ago

1.1.6

2 months ago

1.1.5

2 months ago

1.1.4

3 months ago

1.1.3

3 months ago

1.1.1

4 months ago

1.1.2

4 months ago

1.1.0

4 months ago

1.0.43

4 months ago

1.0.42

4 months ago

1.0.41

4 months ago

1.0.40

4 months ago

1.0.39

5 months ago

1.0.38

5 months ago

1.0.37

5 months ago

1.0.22

7 months ago

1.0.21

7 months ago

1.0.26

7 months ago

1.0.25

7 months ago

1.0.24

7 months ago

1.0.23

7 months ago

1.0.29

6 months ago

1.0.28

7 months ago

1.0.27

7 months ago

1.0.33

6 months ago

1.0.32

6 months ago

1.0.31

6 months ago

1.0.30

6 months ago

1.0.36

5 months ago

1.0.35

5 months ago

1.0.34

5 months ago

1.0.20

8 months ago

1.0.19

8 months ago

1.0.18

8 months ago

1.0.17

8 months ago

1.0.16

9 months ago

1.0.15

10 months ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.2

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.1

2 years ago

1.0.0

2 years ago