Skip to content

Commit

Permalink
feat(ui): add gitlab sso support
Browse files Browse the repository at this point in the history
  • Loading branch information
liangfung committed May 22, 2024
1 parent 8b073ce commit 11b4bce
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,13 @@ export const PROVIDER_METAS: Array<{
domain: 'google.com',
displayName: 'Google'
}
},
{
name: 'gitlab',
enum: OAuthProvider.Gitlab,
meta: {
domain: 'gitlab.com',
displayName: 'GitLab'
}
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,16 @@ export default function OAuthCredentialForm({
Google
</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem
value={OAuthProvider.Gitlab}
id="r_gitlab"
disabled={!isNew}
/>
<Label className="cursor-pointer" htmlFor="r_gitlab">
GitLab
</Label>
</div>
</RadioGroup>
</FormControl>
<FormMessage />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,19 @@ const OAuthCredentialList = () => {
query: oauthCredential,
variables: { provider: OAuthProvider.Google }
})
const [{ data: gitlabData, fetching: fetchingGitlab }] = useQuery({
query: oauthCredential,
variables: { provider: OAuthProvider.Gitlab }
})

const isLoading = fetchingGithub || fetchingGoogle
const isLoading = fetchingGithub || fetchingGoogle || fetchingGitlab
const credentialList = React.useMemo(() => {
return compact([githubData?.oauthCredential, googleData?.oauthCredential])
}, [githubData, googleData])
return compact([
githubData?.oauthCredential,
googleData?.oauthCredential,
gitlabData?.oauthCredential
])
}, [githubData, googleData, gitlabData])

const router = useRouter()
const createButton = (
Expand Down Expand Up @@ -100,7 +108,7 @@ const OAuthCredentialList = () => {
)
})}
</div>
{credentialList.length < 2 && (
{credentialList.length < 3 && (
<div className="mt-4 flex justify-end">{createButton}</div>
)}
</div>
Expand Down Expand Up @@ -144,4 +152,4 @@ const OauthCredentialCard = ({
)
}

export { OAuthCredentialList as OauthCredentialList }
export { OAuthCredentialList }
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Metadata } from 'next'

import { OauthCredentialList } from './components/oauth-credential-list'
import { OAuthCredentialList } from './components/oauth-credential-list'

export const metadata: Metadata = {
title: 'SSO'
}

export default function IndexPage() {
return <OauthCredentialList />
return <OAuthCredentialList />
}
9 changes: 7 additions & 2 deletions ee/tabby-ui/app/auth/signin/components/signin-section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import useRouterStuff from '@/lib/hooks/use-router-stuff'
import { useAllowSelfSignup } from '@/lib/hooks/use-server-info'
import { useSession, useSignIn } from '@/lib/tabby/auth'
import fetcher from '@/lib/tabby/fetcher'
import { IconGithub, IconGoogle, IconSpinner } from '@/components/ui/icons'
import { IconGitLab, IconGithub, IconGoogle, IconSpinner } from '@/components/ui/icons'

import UserSignInForm from './user-signin-form'

Expand Down Expand Up @@ -78,7 +78,7 @@ export default function SigninSection() {
<div className="grow border-t "></div>
</div>
)}
<div className="mx-auto flex items-center gap-6">
<div className="mx-auto flex items-center gap-8">
{data?.includes('github') && (
<a href={`/oauth/signin?provider=github`}>
<IconGithub className="h-8 w-8" />
Expand All @@ -89,6 +89,11 @@ export default function SigninSection() {
<IconGoogle className="h-8 w-8" />
</a>
)}
{data?.includes('gitlab') && (
<a href={`/oauth/signin?provider=gitlab`}>
<IconGitLab className="h-8 w-8" />
</a>
)}
</div>
{!!errorMessage && (
<div className="mt-4 text-destructive">{errorMessage}</div>
Expand Down
2 changes: 1 addition & 1 deletion ee/tabby-webserver/src/routes/oauth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async fn has_provider(auth: &Arc<dyn AuthenticationService>, x: &OAuthProvider)
}

async fn providers_handler(state: State<OAuthState>) -> Json<Vec<OAuthProvider>> {
let candidates = vec![OAuthProvider::Google, OAuthProvider::Github];
let candidates = vec![OAuthProvider::Google, OAuthProvider::Github, OAuthProvider::Gitlab];
let mut providers = vec![];

for x in candidates {
Expand Down

0 comments on commit 11b4bce

Please sign in to comment.