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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: github social auth implementation #156

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
65 changes: 11 additions & 54 deletions resources/pages/access/components/user-login-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
FormControl,
FormMessage,
} from "@/components/ui/form"
import { Icons } from "@/components/icons"

interface UserLoginFormProps extends React.HTMLAttributes<HTMLDivElement> {}
const formSchema = z.object({
Expand Down Expand Up @@ -151,64 +152,20 @@ export function UserLoginForm({ className, ...props }: UserLoginFormProps) {
</div>
<Button variant="outline" type="button" disabled={isLoading}>
{isLoading ? (
<svg
className="animate-spin -ml-1 mr-3 h-5 w-5 text-white"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
>
<circle
className="opacity-25"
cx="12"
cy="12"
r="10"
stroke="currentColor"
strokeWidth="4"
></circle>
<path
className="opacity-75"
fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
></path>
</svg>
<Icons.spinner className="mr-2 h-5 w-5" />
) : (
<svg viewBox="0 0 18 18" className="w-5 mr-2 h-5">
<title>Google</title>
<desc>Google "G" Logo</desc>
<defs></defs>
<g stroke="none" strokeWidth="1" fill="none" fillRule="evenodd">
<g>
<g id="Group">
<g id="logo_google_48dp">
<path
id="Shape"
d="M17.64,9.20454545 C17.64,8.56636364 17.5827273,7.95272727 17.4763636,7.36363636 L9,7.36363636 L9,10.845 L13.8436364,10.845 C13.635,11.97 13.0009091,12.9231818 12.0477273,13.5613636 L12.0477273,15.8195455 L14.9563636,15.8195455 C16.6581818,14.2527273 17.64,11.9454545 17.64,9.20454545 L17.64,9.20454545 Z"
fill="#4285F4"
></path>
<path
id="Shape"
d="M9,18 C11.43,18 13.4672727,17.1940909 14.9563636,15.8195455 L12.0477273,13.5613636 C11.2418182,14.1013636 10.2109091,14.4204545 9,14.4204545 C6.65590909,14.4204545 4.67181818,12.8372727 3.96409091,10.71 L0.957272727,10.71 L0.957272727,13.0418182 C2.43818182,15.9831818 5.48181818,18 9,18 L9,18 Z"
fill="#34A853"
></path>
<path
id="Shape"
d="M3.96409091,10.71 C3.78409091,10.17 3.68181818,9.59318182 3.68181818,9 C3.68181818,8.40681818 3.78409091,7.83 3.96409091,7.29 L3.96409091,4.95818182 L0.957272727,4.95818182 C0.347727273,6.17318182 0,7.54772727 0,9 C0,10.4522727 0.347727273,11.8268182 0.957272727,13.0418182 L3.96409091,10.71 L3.96409091,10.71 Z"
fill="#FBBC05"
></path>
<path
id="Shape"
d="M9,3.57954545 C10.3213636,3.57954545 11.5077273,4.03363636 12.4404545,4.92545455 L15.0218182,2.34409091 C13.4631818,0.891818182 11.4259091,0 9,0 C5.48181818,0 2.43818182,2.01681818 0.957272727,4.95818182 L3.96409091,7.29 C4.67181818,5.16272727 6.65590909,3.57954545 9,3.57954545 L9,3.57954545 Z"
fill="#EA4335"
></path>
<polygon id="Shape" points="0 0 18 0 18 18 0 18"></polygon>
</g>
</g>
</g>
</g>
</svg>
<Icons.google className="mr-2 h-5 w-5" />
)}{" "}
Sign in with Google
</Button>
<Button variant="outline" type="button" disabled={isLoading}>
{isLoading ? (
<Icons.spinner className="mr-2 h-5 w-5" />
) : (
<Icons.gitHub className="mr-2 h-5 w-5" />
)}{" "}
Sign in with GitHub
</Button>
</div>
)
}
67 changes: 12 additions & 55 deletions resources/pages/access/components/user-registration-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
FormControl,
FormMessage,
} from "@/components/ui/form"
import { Icons } from "@/components/icons"

interface UserRegistrationFormProps
extends React.HTMLAttributes<HTMLDivElement> {}
Expand Down Expand Up @@ -152,63 +153,19 @@ export function UserRegistrationForm({
</div>
<Button variant="outline" type="button" disabled={isLoading}>
{isLoading ? (
<svg
className="animate-spin -ml-1 mr-3 h-5 w-5 text-white"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
>
<circle
className="opacity-25"
cx="12"
cy="12"
r="10"
stroke="currentColor"
strokeWidth="4"
></circle>
<path
className="opacity-75"
fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
></path>
</svg>
<Icons.spinner className="mr-2 h-5 w-5" />
) : (
<svg viewBox="0 0 18 18" className="w-5 mr-2 h-5">
<title>Google</title>
<desc>Google "G" Logo</desc>
<defs></defs>
<g stroke="none" strokeWidth="1" fill="none" fill-rule="evenodd">
<g>
<g id="Group">
<g>
<path
id="Shape"
d="M17.64,9.20454545 C17.64,8.56636364 17.5827273,7.95272727 17.4763636,7.36363636 L9,7.36363636 L9,10.845 L13.8436364,10.845 C13.635,11.97 13.0009091,12.9231818 12.0477273,13.5613636 L12.0477273,15.8195455 L14.9563636,15.8195455 C16.6581818,14.2527273 17.64,11.9454545 17.64,9.20454545 L17.64,9.20454545 Z"
fill="#4285F4"
></path>
<path
id="Shape"
d="M9,18 C11.43,18 13.4672727,17.1940909 14.9563636,15.8195455 L12.0477273,13.5613636 C11.2418182,14.1013636 10.2109091,14.4204545 9,14.4204545 C6.65590909,14.4204545 4.67181818,12.8372727 3.96409091,10.71 L0.957272727,10.71 L0.957272727,13.0418182 C2.43818182,15.9831818 5.48181818,18 9,18 L9,18 Z"
fill="#34A853"
></path>
<path
id="Shape"
d="M3.96409091,10.71 C3.78409091,10.17 3.68181818,9.59318182 3.68181818,9 C3.68181818,8.40681818 3.78409091,7.83 3.96409091,7.29 L3.96409091,4.95818182 L0.957272727,4.95818182 C0.347727273,6.17318182 0,7.54772727 0,9 C0,10.4522727 0.347727273,11.8268182 0.957272727,13.0418182 L3.96409091,10.71 L3.96409091,10.71 Z"
fill="#FBBC05"
></path>
<path
id="Shape"
d="M9,3.57954545 C10.3213636,3.57954545 11.5077273,4.03363636 12.4404545,4.92545455 L15.0218182,2.34409091 C13.4631818,0.891818182 11.4259091,0 9,0 C5.48181818,0 2.43818182,2.01681818 0.957272727,4.95818182 L3.96409091,7.29 C4.67181818,5.16272727 6.65590909,3.57954545 9,3.57954545 L9,3.57954545 Z"
fill="#EA4335"
></path>
<polygon id="Shape" points="0 0 18 0 18 18 0 18"></polygon>
</g>
</g>
</g>
</g>
</svg>
<Icons.google className="mr-2 h-5 w-5" />
)}{" "}
Sign in with Google
Sign up with Google
</Button>
<Button variant="outline" type="button" disabled={isLoading}>
{isLoading ? (
<Icons.spinner className="mr-2 h-5 w-5" />
) : (
<Icons.gitHub className="mr-2 h-5 w-5" />
)}{" "}
Sign up with GitHub
</Button>
</div>
)
Expand Down
2 changes: 2 additions & 0 deletions src/app/domain/accounts/guards.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ async def current_user_from_token(token: Token, connection: ASGIConnection[Any,
exclude=[
constants.OPENAPI_SCHEMA,
constants.HEALTH_ENDPOINT,
urls.GITHUB_OAUTH2_CALLBACK,
urls.GOOGLE_OAUTH2_CALLBACK,
urls.ACCOUNT_LOGIN,
urls.ACCOUNT_REGISTER,
],
Expand Down
2 changes: 2 additions & 0 deletions src/app/domain/accounts/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@
ACCOUNT_CREATE = "/api/users"
ACCOUNT_ASSIGN_ROLE = "/api/roles/{role_slug:str}/assign"
ACCOUNT_REVOKE_ROLE = "/api/roles/{role_slug:str}/revoke"
GITHUB_OAUTH2_CALLBACK = "/api/oauth/github/complete"
GOOGLE_OAUTH2_CALLBACK = "/api/oauth/google/complete"
5 changes: 2 additions & 3 deletions src/app/domain/teams/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ async def get_user_teams(
**kwargs: Any,
) -> tuple[list[Team], int]:
"""Get paginated list and total count of teams that a user can access."""

team_filter = select(TeamMember.id).where(TeamMember.user_id == user_id)
return await self.list_and_count(
*filters,
Team.id.in_(team_filter),
statement=select(Team)
.join(TeamMember, onclause=Team.id == TeamMember.team_id, isouter=False)
.where(TeamMember.user_id == user_id)
.order_by(Team.name)
.options(
selectinload(Team.tags),
Expand Down
Loading