Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(providers): add BoxyHQ SAML Jackson provider #3782

Merged
merged 24 commits into from
Mar 5, 2022
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
1d0b89a
added saml-jackson provider
deepakprabhakara Jan 29, 2022
94fd46b
Merge branch 'main' into boxyhq-saml
deepakprabhakara Feb 2, 2022
94be271
Merge branch 'main' into boxyhq-saml
deepakprabhakara Feb 2, 2022
9aee942
Merge branch 'main' into boxyhq-saml
deepakprabhakara Feb 3, 2022
8955ffd
incorporated code review changes
deepakprabhakara Feb 4, 2022
a727b78
Merge branch 'main' into boxyhq-saml
deepakprabhakara Feb 4, 2022
c0972e0
fixed SAMLJacksonProfile type
deepakprabhakara Feb 4, 2022
bf62a08
Merge branch 'main' into boxyhq-saml
deepakprabhakara Feb 4, 2022
152af78
Merge branch 'main' into boxyhq-saml
deepakprabhakara Feb 5, 2022
d1c2bbf
trying to adjust code for monorepo
deepakprabhakara Feb 5, 2022
98845f2
Merge branch 'main' into boxyhq-saml
deepakprabhakara Feb 6, 2022
32622d8
Merge branch 'main' into boxyhq-saml
deepakprabhakara Feb 6, 2022
c762463
Merge branch 'main' into boxyhq-saml
deepakprabhakara Feb 10, 2022
483634d
Merge branch 'main' into boxyhq-saml
deepakprabhakara Feb 14, 2022
d507c6c
Merge branch 'main' into boxyhq-saml
deepakprabhakara Feb 22, 2022
b6b24bf
Merge branch 'main' into boxyhq-saml
deepakprabhakara Feb 24, 2022
23532f1
Merge branch 'main' into boxyhq-saml
deepakprabhakara Mar 1, 2022
c5ad8a7
cleanup from merge with main
deepakprabhakara Mar 1, 2022
42ee902
updated docs link
deepakprabhakara Mar 1, 2022
afbdc5b
added example
deepakprabhakara Mar 2, 2022
603d1f5
consistent naming
deepakprabhakara Mar 2, 2022
28a2794
Merge branch 'main' into boxyhq-saml
deepakprabhakara Mar 4, 2022
c8dc125
Incorporated code review changes:
deepakprabhakara Mar 4, 2022
ab81e1a
email is guaranteed to be present
deepakprabhakara Mar 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions apps/dev/pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import AppleProvider from "next-auth/providers/apple"
import PatreonProvider from "next-auth/providers/patreon"
import TraktProvider from "next-auth/providers/trakt"
import WorkOSProvider from "next-auth/providers/workos"
import BoxyHQSAMLProvider from "next-auth/providers/boxyhq-saml"

// import { PrismaAdapter } from "@next-auth/prisma-adapter"
// import { PrismaClient } from "@prisma/client"
Expand Down Expand Up @@ -200,6 +201,11 @@ export const authOptions: NextAuthOptions = {
clientId: process.env.WORKOS_ID,
clientSecret: process.env.WORKOS_SECRET,
}),
BoxyHQSAMLProvider({
issuer: process.env.BOXYHQSAML_ISSUER || "https://jackson-demo.boxyhq.com",
clientId: process.env.BOXYHQSAML_ID || "tenant=boxyhq.com&product=saml-demo.boxyhq.com",
clientSecret: process.env.BOXYHQSAML_SECRET || "dummy",
deepakprabhakara marked this conversation as resolved.
Show resolved Hide resolved
}),
],
debug: true,
theme: {
Expand Down
58 changes: 58 additions & 0 deletions docs/docs/providers/boxyhq-saml.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
id: boxyhq-saml
title: BoxyHQ SAML Jackson
---

## Documentation

BoxyHQ SAML Jackson is an open source service that handles the SAML login flow as an OAuth 2.0 flow, abstracting away all the complexities of the SAML protocol.

You can deploy SAML Jackson as a separate service or embed it into your app using our NPM library. [Check out the documentation for more details](https://boxyhq.com/docs/jackson/deploy)

## Configuration

SAML login requires a configuration for every tenant of yours. One common method is to use the domain for an email address to figure out which tenant they belong to. You can also use a unique tenant ID (string) from your backend for this, typically some kind of account or organization ID.

Check out the [documentation](https://boxyhq.com/docs/jackson/saml-flow#2-saml-config-api) for more details.

## Options

The **BoxyHQ SAML Provider** comes with a set of default options:

- [BoxyHQ Provider options](https://github.com/nextauthjs/next-auth/tree/main/packages/next-auth/src/providers/boxyhq-saml.ts)

You can override any of the options to suit your own use case.

## Example

```ts
import BoxyHQSAMLProvider from "next-auth/providers/boxyhq-saml"
...
providers: [
BoxyHQSAMLProvider({
issuer: "http://localhost:5000",
clientId: "dummy", // The dummy here is necessary since we'll pass tenant and product custom attributes in the client code
clientSecret: "dummy", // The dummy here is necessary since we'll pass tenant and product custom attributes in the client code
Comment on lines +34 to +35
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that I understand this correctly. These values are always dummy? 馃

It might be my limited knowledge of SAML, but setting a hardcoded clientSecret does not sound right in OAuth 2.0. What am I missing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@balazsorban44 Please see here - #3782 (comment). User can opt for a proper clientSecret or the convenience of tenant and product.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also this configuration can be set during deployment to change the default dummy value - https://boxyhq.com/docs/jackson/deploy/env-variables#client_secret_verifier

})
}
...
```

On the client side you'll need to pass additional parameters `tenant` and `product` to the `signIn` function. This will allow SAML Jackson to figure out the right SAML configuration and take your user to the right SAML Identity Provider to sign them in.

```tsx
import { signIn } from "next-auth/react";
...

// Map your users's email to a tenant and product
const tenant = email.split("@")[1];
const product = 'my_awesome_product';
...
<Button
onClick={async (event) => {
event.preventDefault();

signIn("saml", {}, { tenant, product });
deepakprabhakara marked this conversation as resolved.
Show resolved Hide resolved
}}>
...
```
37 changes: 37 additions & 0 deletions packages/next-auth/src/providers/boxyhq-saml.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { OAuthConfig, OAuthUserConfig } from "."

export interface SAMLJacksonProfile {
id: string;
deepakprabhakara marked this conversation as resolved.
Show resolved Hide resolved
email?: string;
deepakprabhakara marked this conversation as resolved.
Show resolved Hide resolved
firstName?: string | null;
lastName?: string | null;
deepakprabhakara marked this conversation as resolved.
Show resolved Hide resolved
}

export default function SAMLJackson<
P extends Record<string, any> = SAMLJacksonProfile
>(options: OAuthUserConfig<P>): OAuthConfig<P> {
return {
id: "boxyhq-saml",
name: "BoxyHQ SAML Jackson",
type: "oauth",
version: "2.0",
checks: ["pkce", "state"],
authorization: {
url: `${options.issuer}/api/oauth/authorize`,
params: {
provider: "saml",
},
},
token: `${options.issuer}/api/oauth/token`,
userinfo: `${options.issuer}/api/oauth/userinfo`,
profile(profile) {
return {
id: profile.id,
email: profile.email || "",
deepakprabhakara marked this conversation as resolved.
Show resolved Hide resolved
name: [profile.firstName, profile.lastName].filter(Boolean).join(" "),
image: null,
}
},
options,
}
}