Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/2_bug_provider.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ body:
- "Yandex"
- "Zoho"
- "Zoom"
- "Ztrust"
validations:
required: true
- type: textarea
Expand Down
4 changes: 4 additions & 0 deletions apps/dev/nextjs/.env.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ AUTH_KEYCLOAK_ID=
AUTH_KEYCLOAK_SECRET=
AUTH_KEYCLOAK_ISSUER=

AUTH_ZTRUST_ID=
AUTH_ZTRUST_SECRET=
AUTH_ZTRUST_ISSUER=

AUTH_LINE_ID=
AUTH_LINE_SECRET=

Expand Down
2 changes: 2 additions & 0 deletions apps/dev/nextjs/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import NextAuth from "next-auth"
import Credentials from "next-auth/providers/credentials"
import Keycloak from "next-auth/providers/keycloak"
import GitHub from "next-auth/providers/github"
import Ztrust from "next-auth/providers/ztrust"

// import { PrismaClient } from "@prisma/client"
// import { PrismaAdapter } from "@auth/prisma-adapter"
Expand Down Expand Up @@ -68,6 +69,7 @@ export const { handlers, auth, signIn, signOut, unstable_update } = NextAuth({
}),
GitHub,
Keycloak,
Ztrust,
],

callbacks: {
Expand Down
105 changes: 105 additions & 0 deletions docs/pages/getting-started/providers/ztrust.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { Callout } from "nextra/components"
import { Code } from "@/components/Code"

<img align="right" src="/img/providers/ztrust.svg" height="64" width="64" />

# Ztrust Provider

## Resources

- [Ztrust OIDC documentation](https://ztrust.gitbook.io/ztrust-documentation/user-manual-ztrust-v4.1/5.-securing-applications)

## Setup

### Callback URL

<Code>
<Code.Next>

```bash
https://example.com/api/auth/callback/ztrust
```

</Code.Next>
<Code.Qwik>

```bash
https://example.com/auth/callback/ztrust
```

</Code.Qwik>
<Code.Svelte>

```bash
https://example.com/auth/callback/ztrust
```

</Code.Svelte>
</Code>

### Environment Variables

```
AUTH_ZTRUST_ID
AUTH_ZTRUST_SECRET
AUTH_ZTRUST_ISSUER
```

### Configuration

<Code>
<Code.Next>

```ts filename="/auth.ts"
import NextAuth from "next-auth"
import Ztrust from "next-auth/providers/ztrust"

export const { handlers, auth, signIn, signOut } = NextAuth({
providers: [Ztrust],
})
```

</Code.Next>
<Code.Qwik>

```ts filename="/src/routes/plugin@auth.ts"
import { QwikAuth$ } from "@auth/qwik"
import Ztrust from "@auth/qwik/providers/ztrust"

export const { onRequest, useSession, useSignIn, useSignOut } = QwikAuth$(
() => ({
providers: [Ztrust],
})
)
```

</Code.Qwik>
<Code.Svelte>

```ts filename="/src/auth.ts"
import { SvelteKitAuth } from "@auth/sveltekit"
import Ztrust from "@auth/sveltekit/providers/ztrust"

export const { handle, signIn, signOut } = SvelteKitAuth({
providers: [Ztrust],
})
```

</Code.Svelte>
<Code.Express>

```ts filename="/src/app.ts"
import { ExpressAuth } from "@auth/express"
import Ztrust from "@auth/express/providers/ztrust"

app.use("/auth/*", ExpressAuth({ providers: [Ztrust] }))
```

</Code.Express>
</Code>

Enable the "Client Authentication" option to retrieve your client secret in the Credentials tab.

Prior to v20, create an `openid-connect` client in ztrust with "confidential" as the "Access Type".

- Issuer should include the realm – e.g. `https://my-ztrust-domain.com/realms/My_Realm`
88 changes: 88 additions & 0 deletions docs/public/img/providers/ztrust.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
88 changes: 88 additions & 0 deletions docs/static/img/providers/ztrust.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
120 changes: 120 additions & 0 deletions packages/core/src/providers/ztrust.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/**
* <div class="provider" style={{backgroundColor: "#000", display: "flex", justifyContent: "space-between", color: "#fff", padding: 16}}>
* <span>Built-in <b>Ztrust</b> integration.</span>
* <a href="https://sso.ztrust.in">
* <img style={{display: "block"}} src="https://authjs.dev/img/providers/keycloak.svg" height="48" width="48"/>
* </a>
* </div>
*
* @module providers/ztrust
*/
import type { OIDCConfig, OIDCUserConfig } from "./index.js"

interface User {
id: string
name: string
email: string
image?: string
[key: string]: any
}

export interface ztrustProfile extends Record<string, any> {
exp: number
iat: number
auth_time: number
jti: string
iss: string
aud: string
sub: string
typ: string
azp: string
session_state: string
at_hash: string
acr: string
sid: string
email_verified: boolean
name: string
preferred_username: string
given_name: string
family_name: string
email: string
picture: string
user: User
groups?: string[]
}

/**
* Add Ztrust login to your page.
*
* ### Setup
*
* #### Callback URL
* ```
* https://example.com/api/auth/callback/ztrust
* ```
*
* #### Configuration
*```ts
* import { Auth } from "@auth/core"
* import Ztrust from "@auth/core/providers/ztrust"
*
* const request = new Request(origin)
* const response = await Auth(request, {
* providers: [
* Ztrust({
* clientId: ZTRUST_CLIENT_ID,
* clientSecret: ZTRUST_CLIENT_SECRET,
* issuer: ZTRUST_ISSUER,
* }),
* ],
* })
* ```
*
* ### Resources
*
* - [Ztrust OIDC documentation](https://ztrust.gitbook.io/ztrust-documentation/user-manual-ztrust-v4.1/5.-securing-applications)
*
* :::tip
*
* Create an openid-connect client in Ztrust with "confidential" as the "Access Type".
*
* :::
*
* :::note
*
* issuer should include the realm – e.g. https://ztrust-domain.com/realms/My_Realm_name
*
* :::
* ### Notes
*
* By default, Auth.js assumes that the Ztrust provider is
* based on the [Open ID Connect](https://openid.net/specs/openid-connect-core-1_0.html) specification.
*
* :::tip
*
* The Ztrust provider comes with a [default configuration](https://github.com/nextauthjs/next-auth/blob/main/packages/core/src/providers/ztrust.ts).
* To override the defaults for your use case, check out [customizing a built-in OAuth provider](https://authjs.dev/guides/configuring-oauth-providers).
*
* :::
*
* :::info **Disclaimer**
*
* If you think you found a bug in the default configuration, you can [open an issue](https://authjs.dev/new/provider-issue).
*
* Auth.js strictly adheres to the specification and it cannot take responsibility for any deviation from
* the spec by the provider. You can open an issue, but if the problem is non-compliance with the spec,
* we might not pursue a resolution. You can ask for more help in [Discussions](https://authjs.dev/new/github-discussions).
*
* :::
*/
export default function ZTrust<P extends ztrustProfile>(
options: OIDCUserConfig<P>
): OIDCConfig<P> {
return {
id: "ztrust",
name: "ZTrust",
type: "oidc",
style: { brandColor: "#428bca" },
options,
}
}