mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-04 21:04:37 +08:00
remove slack oauth, allow no email in oauth
This commit is contained in:
parent
c4ae4fc4ed
commit
3c20bf609f
@ -7,4 +7,3 @@
|
||||
|
||||
|
||||
ALTER TYPE "StandardOAuthProviderType" ADD VALUE 'X';
|
||||
ALTER TYPE "StandardOAuthProviderType" ADD VALUE 'SLACK';
|
||||
|
||||
@ -569,7 +569,6 @@ enum StandardOAuthProviderType {
|
||||
LINKEDIN
|
||||
APPLE
|
||||
X
|
||||
SLACK
|
||||
}
|
||||
|
||||
model OAuthToken {
|
||||
|
||||
@ -14,7 +14,6 @@ import { GoogleProvider } from "./providers/google";
|
||||
import { LinkedInProvider } from "./providers/linkedin";
|
||||
import { MicrosoftProvider } from "./providers/microsoft";
|
||||
import { MockProvider } from "./providers/mock";
|
||||
import { SlackProvider } from "./providers/slack";
|
||||
import { SpotifyProvider } from "./providers/spotify";
|
||||
import { XProvider } from "./providers/x";
|
||||
|
||||
@ -30,7 +29,6 @@ const _providers = {
|
||||
bitbucket: BitbucketProvider,
|
||||
linkedin: LinkedInProvider,
|
||||
x: XProvider,
|
||||
slack: SlackProvider,
|
||||
} as const;
|
||||
|
||||
const mockProvider = MockProvider;
|
||||
|
||||
@ -1,46 +0,0 @@
|
||||
import { OAuthBaseProvider, TokenSet } from "./base";
|
||||
import { OAuthUserInfo, validateUserInfo } from "../utils";
|
||||
import { getEnvVariable } from "@stackframe/stack-shared/dist/utils/env";
|
||||
|
||||
export class SlackProvider extends OAuthBaseProvider {
|
||||
private constructor(
|
||||
...args: ConstructorParameters<typeof OAuthBaseProvider>
|
||||
) {
|
||||
super(...args);
|
||||
}
|
||||
|
||||
static async create(options: { clientId: string, clientSecret: string }) {
|
||||
return new SlackProvider(
|
||||
...(await OAuthBaseProvider.createConstructorArgs({
|
||||
issuer: "https://slack.com",
|
||||
authorizationEndpoint: "https://slack.com/oauth/v2/authorize",
|
||||
tokenEndpoint: "https://slack.com/api/oauth.v2.access",
|
||||
redirectUri:
|
||||
getEnvVariable("STACK_BASE_URL") +
|
||||
"/api/v1/auth/oauth/callback/slack",
|
||||
baseScope: "",
|
||||
authorizationExtraParams: {
|
||||
user_scope: "email,profile,openid",
|
||||
},
|
||||
...options,
|
||||
}))
|
||||
);
|
||||
}
|
||||
|
||||
async postProcessUserInfo(tokenSet: TokenSet): Promise<OAuthUserInfo> {
|
||||
const userInfo = await fetch(
|
||||
"https://slack.com/api/openid.connect.userInfo", {
|
||||
headers: {
|
||||
Authorization: `Bearer ${tokenSet.accessToken}`,
|
||||
}
|
||||
}
|
||||
).then(res => res.json());
|
||||
return validateUserInfo({
|
||||
accountId: userInfo.sub?.toString(),
|
||||
displayName: userInfo.name,
|
||||
email: userInfo.email,
|
||||
profileImageUrl: userInfo.picture,
|
||||
emailVerified: userInfo.email_verified,
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -32,12 +32,14 @@ export class XProvider extends OAuthBaseProvider {
|
||||
}
|
||||
).then((res) => res.json());
|
||||
|
||||
console.log("userInfo", userInfo);
|
||||
|
||||
return validateUserInfo({
|
||||
accountId: userInfo?.id?.toString(),
|
||||
displayName: userInfo.name || userInfo.username,
|
||||
// email: undefined, // There is no way of getting email from X Oauth2.0 API
|
||||
email: null, // There is no way of getting email from X Oauth2.0 API
|
||||
profileImageUrl: userInfo.profile_image_url as any,
|
||||
emailVerified: false,
|
||||
});
|
||||
}, { expectNoEmail: true });
|
||||
}
|
||||
}
|
||||
@ -6,11 +6,17 @@ export type OAuthUserInfo = yup.InferType<typeof OAuthUserInfoSchema>;
|
||||
const OAuthUserInfoSchema = yupObject({
|
||||
accountId: yupString().min(1).required(),
|
||||
displayName: yupString().nullable().default(null),
|
||||
email: yupString().email().required(),
|
||||
email: yupString().email().nullable().default(null),
|
||||
profileImageUrl: yupString().nullable().default(null),
|
||||
emailVerified: yupBoolean().default(false),
|
||||
});
|
||||
|
||||
export function validateUserInfo(userInfo: Partial<yup.InferType<typeof OAuthUserInfoSchema>>): OAuthUserInfo {
|
||||
export function validateUserInfo(
|
||||
userInfo: Partial<yup.InferType<typeof OAuthUserInfoSchema>>,
|
||||
options?: { expectNoEmail?: boolean }
|
||||
): OAuthUserInfo {
|
||||
if (!options?.expectNoEmail && !userInfo.email) {
|
||||
throw new Error("Email is required");
|
||||
}
|
||||
return OAuthUserInfoSchema.validateSync(userInfo);
|
||||
}
|
||||
@ -28,7 +28,6 @@ function toTitle(id: string) {
|
||||
bitbucket: "Bitbucket",
|
||||
linkedin: "LinkedIn",
|
||||
x: "X",
|
||||
slack: "Slack",
|
||||
}[id];
|
||||
}
|
||||
|
||||
|
||||
@ -12,7 +12,6 @@ const mockedProviders = [
|
||||
"gitlab",
|
||||
"bitbucket",
|
||||
"x",
|
||||
"slack",
|
||||
];
|
||||
|
||||
const configuration: Configuration = {
|
||||
|
||||
@ -68,11 +68,6 @@ To use your own OAuth provider setups in production, follow these steps for each
|
||||
Callback URL:
|
||||
`https://api.stack-auth.com/api/v1/auth/oauth/callback/x`
|
||||
</Tab>
|
||||
<Tab title="Slack">
|
||||
[X OAuth Setup Guide](https://api.slack.com/authentication/oauth-v2)
|
||||
Callback URL:
|
||||
`https://api.stack-auth.com/api/v1/auth/oauth/callback/slack`
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
2. **Enter OAuth Credentials**: Go to the `Auth Methods` section in the Stack dashboard, open the provider's settings, switch from shared keys to custom keys, and enter the client ID and client secret.
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
export const standardProviders = ["google", "github", "microsoft", "spotify", "facebook", "discord", "gitlab", "bitbucket", "linkedin", "apple", "x", "slack"] as const;
|
||||
export const standardProviders = ["google", "github", "microsoft", "spotify", "facebook", "discord", "gitlab", "bitbucket", "linkedin", "apple", "x"] as const;
|
||||
// No more shared providers should be added except for special cases
|
||||
export const sharedProviders = ["google", "github", "microsoft", "spotify"] as const;
|
||||
export const allProviders = standardProviders;
|
||||
|
||||
@ -148,31 +148,6 @@ function XIcon({ iconSize } : { iconSize: number} ) {
|
||||
);
|
||||
}
|
||||
|
||||
function SlackIcon({ iconSize } : { iconSize: number} ) {
|
||||
return (
|
||||
<svg width={iconSize} height={iconSize} viewBox="0 0 54 54" xmlns="http://www.w3.org/2000/svg">
|
||||
<g fill="none" fill-rule="evenodd">
|
||||
<path
|
||||
d="M19.712.133a5.381 5.381 0 0 0-5.376 5.387 5.381 5.381 0 0 0 5.376 5.386h5.376V5.52A5.381 5.381 0 0 0 19.712.133m0 14.365H5.376A5.381 5.381 0 0 0 0 19.884a5.381 5.381 0 0 0 5.376 5.387h14.336a5.381 5.381 0 0 0 5.376-5.387 5.381 5.381 0 0 0-5.376-5.386"
|
||||
fill="#44BEDF"
|
||||
></path>
|
||||
<path
|
||||
d="M53.76 19.884a5.381 5.381 0 0 0-5.376-5.386 5.381 5.381 0 0 0-5.376 5.386v5.387h5.376a5.381 5.381 0 0 0 5.376-5.387m-14.336 0V5.52A5.381 5.381 0 0 0 34.048.133a5.381 5.381 0 0 0-5.376 5.387v14.364a5.381 5.381 0 0 0 5.376 5.387 5.381 5.381 0 0 0 5.376-5.387"
|
||||
fill="#2EB67D"
|
||||
></path>
|
||||
<path
|
||||
d="M34.048 54a5.381 5.381 0 0 0 5.376-5.387 5.381 5.381 0 0 0-5.376-5.386h-5.376v5.386A5.381 5.381 0 0 0 34.048 54m0-14.365h14.336a5.381 5.381 0 0 0 5.376-5.386 5.381 5.381 0 0 0-5.376-5.387H34.048a5.381 5.381 0 0 0-5.376 5.387 5.381 5.381 0 0 0 5.376 5.386"
|
||||
fill="#ECB22E"
|
||||
></path>
|
||||
<path
|
||||
d="M0 34.249a5.381 5.381 0 0 0 5.376 5.386 5.381 5.381 0 0 0 5.376-5.386v-5.387H5.376A5.381 5.381 0 0 0 0 34.25m14.336-.001v14.364A5.381 5.381 0 0 0 19.712 54a5.381 5.381 0 0 0 5.376-5.387V34.25a5.381 5.381 0 0 0-5.376-5.387 5.381 5.381 0 0 0-5.376 5.387"
|
||||
fill="#E01E5A"
|
||||
></path>
|
||||
</g>
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
|
||||
const changeColor = (c: Color, value: number) => {
|
||||
if (c.isLight()) {
|
||||
value = -value;
|
||||
@ -303,15 +278,6 @@ export function OAuthButton({
|
||||
};
|
||||
break;
|
||||
}
|
||||
case 'slack': {
|
||||
style = {
|
||||
backgroundColor: "#611f69",
|
||||
textColor: "#fff",
|
||||
name: "Slack",
|
||||
icon: <SlackIcon iconSize={iconSize} />,
|
||||
};
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
style = {
|
||||
name: provider,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user