Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
victoriaxyz committed Oct 29, 2024
2 parents ca3c5e4 + 01dd427 commit dc5276d
Show file tree
Hide file tree
Showing 35 changed files with 625 additions and 912 deletions.
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
* @clerk/docs

# Help keep docs quickstart content in sync with Dashboard
docs/quickstarts/* @clerk/growth
77 changes: 57 additions & 20 deletions docs/authentication/social-connections/slack.mdx
Original file line number Diff line number Diff line change
@@ -1,39 +1,76 @@
---
title: Add Slack as a social connection
description: Learn how to set up social connection with Slack.
description: Learn how to allow users to sign up and sign in to your Clerk app with their Slack account using OAuth.
---

How to set up social connection with Slack
<TutorialHero
beforeYouStart={[
{
title: "A Clerk app is required.",
link: "/docs/quickstarts/setup-clerk",
icon: "clerk",
},
{
title: "A Slack account is required.",
link: "https://slack.com/get-started#/createnew",
icon: "user-circle",
},
]}
>
- Use Slack to authenticate users with OAuth
</TutorialHero>

## Overview
Enabling OAuth with [Slack](https://api.slack.com/authentication) allows your users to sign up and sign in to your Clerk app with their Slack account.

Adding social connection with Slack to your app with Clerk is done in a few steps - you only need to set the **Client ID**, **Client Secret** and **Authorized redirect URL** in your instance settings.
## Configure for your development instance

> [!NOTE]
> Please note that Sign in with Slack doesn't support any additional OAuth scopes other than **openid**, **email**, **profile**, which are requested by default
For _development instances_, Clerk uses preconfigured shared OAuth credentials and redirect URIs—no other configuration is needed.

To make the development flow as smooth as possible, Clerk uses preconfigured shared OAuth credentials and redirect URIs for development instances - no other configuration is needed.
1. In the Clerk Dashboard, navigate to the [**SSO Connections**](https://dashboard.clerk.com/last-active?path=user-authentication/sso-connections) page.
1. Select **Add connection** and select **For all users**.
1. In the **Choose provider** dropdown, select **Slack**.
1. Select **Add connection**.

For production instances, you will need to generate your own Client ID and Client secret using your Slack account.
## Configure for your production instance

> [!NOTE]
> The purpose of this guide is to help you create a Slack OAuth app - if you're looking for step-by-step instructions using Clerk to add social connection (OAuth) to your application, follow the [Social connection (OAuth) guide](/docs/authentication/social-connections/oauth).
For _production instances_, you must provide custom credentials which involves generating your own **Client ID** and **Client Secret** using your Slack account.

## Before you start
To make the setup process easier, it's recommended to keep two browser tabs open: one for your [Clerk Dashboard](https://dashboard.clerk.com/last-active?path=user-authentication/sso-connections) and one for your [Slack's API Platform](https://api.slack.com/).

- You need to create a Clerk Application in your [Clerk Dashboard](https://dashboard.clerk.com/). For more information, check out our [Set up your application guide](/docs/quickstarts/setup-clerk).
- You need to have a Slack account. To create one, [click here](https://slack.com/get-started#/createnew).
<Steps>
### Enable Slack as a social connection in Clerk

## Configuring Slack social connection
1. In the Clerk Dashboard, navigate to the [**SSO Connections**](https://dashboard.clerk.com/last-active?path=user-authentication/sso-connections) page.
1. Select **Add connection** and select **For all users**.
1. In the **Choose provider** dropdown, select **Slack**.
1. Ensure that both **Enable for sign-up and sign-in** and **Use custom credentials** are toggled on.
1. Save the **Redirect URI** somewhere secure. Keep the modal and page open.

First, you need to create a new OAuth Slack app. On the main [Slack apps page](https://api.slack.com/apps), click on **Create new app**. On the modal that pops up, choose **From scratch,** enter your application name and choose a Slack workspace to associate with it.
### Create a Slack app

![Creating a new application](/docs/images/authentication-providers/slack/creating-new-application.jpg)
1. In the Slack API Platform, navigate to the [**Your Apps**](https://api.slack.com/apps) page and select **Create an App**.
1. A modal will open. Depending on your app needs, select either **From a manifest** for **From scratch**. For more information on which to choose, refer to [Slack's doc on manifests](https://api.slack.com/reference/manifests).
1. After following the respective steps for either option, you'll be redirected to the **App Credentials** page. Save the **Client ID** and **Client Secret** somewhere secure. Keep this page open.
1. In the sidebar, navigate to the **OAuth & Permissions** page.
1. Scroll down to the **Redirect URLs** section and paste the **Redirect URI** you saved from the Clerk Dashboard. Select **Add**, then select **Save URLs**.

Navigate to the [Clerk Dashboard](https://dashboard.clerk.com/last-active?path=user-authentication/sso-connections). In the top navigation, select **Configure**. Then in the sidebar, select **SSO Connections**. Select the **Add connection** button, and select **For all users**. In the **Choose provider** dropdown, select **Slack**. Toggle on **Use custom credentials** and copy **Redirect URI**. Navigate to **OAuth & Permissions > Redirect URLs** and paste the value to add a new record.
### Set the Client ID and Client Secret in your Clerk Dashboard

![Copying values from the Slack dashboard](/docs/images/authentication-providers/slack/copying-values-from-slack-dashboard.jpg)
1. Navigate back to your Clerk Dashboard where the modal should still be open. Paste the **Client ID** and **Client Secret** values that you saved into the respective fields.
1. Select **Add connection**.

Copy the **Client ID** and **Client secret** as shown in the above image from the Basic Information menu of your app. Go back to the Clerk Dashboard and paste them into the respective fields.
> [!NOTE]
> If the modal or page is not still open, navigate to the [**SSO Connections**](https://dashboard.clerk.com/last-active?path=user-authentication/sso-connections) page in the Clerk Dashboard. Select the **Slack** connection. Under **Use custom credentials**, you can paste the **Client ID** and **Client Secret** into their respective fields.
Finally, select **Add connection** so that the settings are applied. Congratulations! Social connection with Slack is now configured for your instance.
### Test your OAuth

The simplest way to test your OAuth is to visit your Clerk app's [Account Portal](/docs/customization/account-portal/overview), which is available for all Clerk apps out-of-the-box.

1. In the Clerk Dashboard, navigate to the [**Account Portal**](https://dashboard.clerk.com/last-active?path=account-portal) page.
1. Next to the **Sign-in** URL, select **Visit**. The URL should resemble:

- **For development**`https://your-domain.accounts.dev/sign-in`
- **For production**`https://accounts.your-domain.com/sign-in`

1. Sign in with your Slack account.
</Steps>
89 changes: 89 additions & 0 deletions docs/backend-requests/handling/js-backend-sdks.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
title: Handling requests with a JS Backend SDK
description: Learn how to handle authenticated requests with one of Clerk's JS Backend SDKs.
---

To handle authenticated requests, use one of the following JS Backend SDKs.

## Clerk Express SDK

The `clerkMiddleware()` function checks the request's cookies and headers for a session JWT. If the user has a valid session, the `clerkMiddleware()` function attaches the [properties](/docs/references/nextjs/auth-object#auth-object-properties) of the authenticated user to the request object.

```js
import { clerkMiddleware } from '@clerk/express'

const app = express()

// Pass no parameters
app.use(clerkMiddleware())

// Pass options
app.use(clerkMiddleware(options))
```

For more information on the Middleware functions and SDK features, see the [Express SDK](/docs/references/express/overview) page.

## Clerk Fastify SDK

The `clerkPlugin` checks the request's cookies and headers for a session JWT. If the user has a valid session, the `clerkPlugin` attaches the [properties](/docs/references/nextjs/auth-object#auth-object-properties) of the authenticated user to the request object.

```ts
import 'dotenv/config'
import Fastify from 'fastify'
import { clerkClient, clerkPlugin, getAuth } from '@clerk/fastify'

const fastify = Fastify({ logger: true })

fastify.register(clerkPlugin)

fastify.get('/', async (request, reply) => {
const { userId } = getAuth(request)

// Protect the route from unauthenticated users
if (!userId) {
return reply.code(403).send({ error: 'Unauthorized request.' })
}

const user = userId ? await clerkClient.users.getUser(userId) : null

return reply.send({
message: 'User retrieved successfully.',
user,
})
})

const start = async () => {
try {
await fastify.listen({ port: 8080 })
} catch (error) {
fastify.log.error(error)
process.exit(1)
}
}

start()
```

For more information on the Clerk plugin and SDK features, see the [Fastify SDK](/docs/quickstarts/fastify) page.

## Clerk Backend SDK

If you're not using Express or Fastify, use the `@clerk/backend` package to access `clerkClient`.

```ts
import { createClerkClient } from '@clerk/backend'

const clerkClient = createClerkClient({
secretKey: process.env.CLERK_SECRET_KEY,
publishableKey: process.env.CLERK_PUBLISHABLE_KEY,
})

const { isSignedIn } = await clerkClient.authenticateRequest(req, {
jwtKey: process.env.CLERK_JWT_KEY,
authorizedParties: ['https://example.com'],
})

if (!isSignedIn) {
return Response.json({ status: 401 })
}
```
49 changes: 15 additions & 34 deletions docs/integrations/webhooks/debug-your-webhooks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,21 @@ Incoming webhook events will never be signed in -- they are coming from a source

The following example shows the recommended Middleware configuration for your webhook routes.

<CodeBlockTabs options={["clerkMiddleware", "authMiddleware"]}>
```tsx {{ filename: 'middleware.tsx' }}
import { clerkMiddleware } from '@clerk/nextjs/server'

// Make sure that the `/api/webhooks/(.*)` route is not protected here
export default clerkMiddleware()

export const config = {
matcher: [
// Skip Next.js internals and all static files, unless found in search params
'/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)',
// Always run for API routes
'/(api|trpc)(.*)',
],
}
```

```tsx {{ filename: 'middleware.tsx', mark: [4] }}
import { authMiddleware } from '@clerk/nextjs/server'

export default authMiddleware({
ignoredRoutes: ['/api/webhooks(.*)'],
})

export const config = {
matcher: [
// Skip Next.js internals and all static files, unless found in search params
'/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)',
// Always run for API routes
'/(api|trpc)(.*)',
],
}
```
</CodeBlockTabs>
```tsx {{ filename: 'middleware.tsx' }}
import { clerkMiddleware } from '@clerk/nextjs/server'

// Make sure that the `/api/webhooks/(.*)` route is not protected here
export default clerkMiddleware()

export const config = {
matcher: [
// Skip Next.js internals and all static files, unless found in search params
'/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)',
// Always run for API routes
'/(api|trpc)(.*)',
],
}
```

## Test the Route Handler or API Route

Expand Down
49 changes: 15 additions & 34 deletions docs/integrations/webhooks/sync-data.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -74,40 +74,21 @@ These steps apply to any Clerk event. To make the setup process easier, it's rec

The following example shows the recommended Middleware configuration for webhook routes.

<CodeBlockTabs options={["clerkMiddleware()", "authMiddleware()"]}>
```tsx {{ filename: 'middleware.ts' }}
import { clerkMiddleware } from '@clerk/nextjs/server'

// Make sure that the `/api/webhooks(.*)` route is not protected here
export default clerkMiddleware()

export const config = {
matcher: [
// Skip Next.js internals and all static files, unless found in search params
'/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)',
// Always run for API routes
'/(api|trpc)(.*)',
],
}
```

```tsx {{ filename: 'middleware.ts', mark: [4] }}
import { authMiddleware } from '@clerk/nextjs/server'

export default authMiddleware({
ignoredRoutes: ['/api/webhooks(.*)'],
})

export const config = {
matcher: [
// Skip Next.js internals and all static files, unless found in search params
'/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)',
// Always run for API routes
'/(api|trpc)(.*)',
],
}
```
</CodeBlockTabs>
```ts {{ filename: 'middleware.ts' }}
import { clerkMiddleware } from '@clerk/nextjs/server'

// Make sure that the `/api/webhooks(.*)` route is not protected here
export default clerkMiddleware()

export const config = {
matcher: [
// Skip Next.js internals and all static files, unless found in search params
'/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)',
// Always run for API routes
'/(api|trpc)(.*)',
],
}
```

### Install `svix`

Expand Down
24 changes: 6 additions & 18 deletions docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -702,8 +702,8 @@
"items": [
[
{
"title": "Node.js & Express",
"href": "/docs/backend-requests/handling/nodejs"
"title": "JS Backend SDKs",
"href": "/docs/backend-requests/handling/js-backend-sdks"
},
{
"title": "Go",
Expand All @@ -718,6 +718,10 @@
{
"title": "Manual JWT Verification",
"href": "/docs/backend-requests/handling/manual-jwt"
},
{
"title": "Node.js (Deprecated)",
"href": "/docs/backend-requests/handling/nodejs"
}
]
]
Expand Down Expand Up @@ -1729,22 +1733,6 @@
]
]
},
{
"title": "Deprecated",
"items": [
[
{
"title": "`authMiddleware()`",
"wrap": false,
"href": "/docs/references/nextjs/auth-middleware"
},
{
"title": "Use Clerk with Next.js 12 and older",
"href": "/docs/references/nextjs/usage-with-older-versions"
}
]
]
},
{
"title": "Demo Repositories",
"items": [
Expand Down
Loading

0 comments on commit dc5276d

Please sign in to comment.