Sso support dess (#348)

* WIP Implemented OAuth

* Added OAUTH2 OIDC support

* update based on the latest changes in the lemmy repo PR

* updating types based on the latest changes in the Lemmy PR

* removed the auto_approve_application

* support registration application with sso

* update to reflect the changes in lemmy

* updated the latest types from main

---------

Co-authored-by: Anthony Lawn <thepaperpilot@gmail.com>
Co-authored-by: privacyguard <privacyguard@users.noreply.github.com>
This commit is contained in:
Dessalines 2024-09-18 09:36:47 -04:00 committed by GitHub
parent 0c7455c60d
commit eb84a74b99
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
26 changed files with 216 additions and 38 deletions

View file

@ -30,6 +30,9 @@ rm src/types/Sensitive.ts
# Change all the bigints to numbers
find src/types -type f -name '*.ts' -exec sed -i 's/bigint/number/g' {} +
# on MacOS:
# find src/types -type f -name '*.ts' -exec sed -i '' -e 's/bigint/number/g' {} \;
node putTypesInIndex.js
prettier -w src

View file

@ -22,6 +22,7 @@ import { CreateCommentLike } from "./types/CreateCommentLike";
import { CreateCommentReport } from "./types/CreateCommentReport";
import { CreateCommunity } from "./types/CreateCommunity";
import { CreateCustomEmoji } from "./types/CreateCustomEmoji";
import { CreateOAuthProvider } from "./types/CreateOAuthProvider";
import { CreatePost } from "./types/CreatePost";
import { CreatePostLike } from "./types/CreatePostLike";
import { CreatePostReport } from "./types/CreatePostReport";
@ -33,15 +34,18 @@ import { DeleteAccount } from "./types/DeleteAccount";
import { DeleteComment } from "./types/DeleteComment";
import { DeleteCommunity } from "./types/DeleteCommunity";
import { DeleteCustomEmoji } from "./types/DeleteCustomEmoji";
import { DeleteOAuthProvider } from "./types/DeleteOAuthProvider";
import { DeletePost } from "./types/DeletePost";
import { DeletePrivateMessage } from "./types/DeletePrivateMessage";
import { DistinguishComment } from "./types/DistinguishComment";
import { EditComment } from "./types/EditComment";
import { EditCommunity } from "./types/EditCommunity";
import { EditCustomEmoji } from "./types/EditCustomEmoji";
import { EditOAuthProvider } from "./types/EditOAuthProvider";
import { EditPost } from "./types/EditPost";
import { EditPrivateMessage } from "./types/EditPrivateMessage";
import { EditSite } from "./types/EditSite";
import { OAuthProvider } from "./types/OAuthProvider";
import { FeaturePost } from "./types/FeaturePost";
import { FollowCommunity } from "./types/FollowCommunity";
import { GetCaptchaResponse } from "./types/GetCaptchaResponse";
@ -139,6 +143,7 @@ import { ListCommentLikesResponse } from "./types/ListCommentLikesResponse";
import { HidePost } from "./types/HidePost";
import { ListMedia } from "./types/ListMedia";
import { ListMediaResponse } from "./types/ListMediaResponse";
import { AuthenticateWithOauth } from "./types/AuthenticateWithOauth";
import { GetRegistrationApplication } from "./types/GetRegistrationApplication";
enum HttpType {
@ -1434,6 +1439,58 @@ export class LemmyHttp {
);
}
/**
* Create a new oauth provider method
*
* `HTTP.POST /oauth_provider`
*/
createOAuthProvider(form: CreateOAuthProvider) {
return this.#wrapper<CreateOAuthProvider, OAuthProvider>(
HttpType.Post,
"/oauth_provider",
form,
);
}
/**
* Edit an existing oauth provider method
*
* `HTTP.PUT /oauth_provider`
*/
editOAuthProvider(form: EditOAuthProvider) {
return this.#wrapper<EditOAuthProvider, OAuthProvider>(
HttpType.Put,
"/oauth_provider",
form,
);
}
/**
* Delete an oauth provider method
*
* `HTTP.Post /oauth_provider/delete`
*/
deleteOAuthProvider(form: DeleteOAuthProvider) {
return this.#wrapper<DeleteOAuthProvider, SuccessResponse>(
HttpType.Post,
"/oauth_provider/delete",
form,
);
}
/**
* Authenticate with OAuth
*
* `HTTP.Post /oauth/authenticate`
*/
authenticateWithOAuth(form: AuthenticateWithOauth) {
return this.#wrapper<AuthenticateWithOauth, LoginResponse>(
HttpType.Post,
"/oauth/authenticate",
form,
);
}
/**
* Fetch federated instances.
*

View file

@ -13,6 +13,7 @@ export { AdminPurgePersonView } from "./types/AdminPurgePersonView";
export { AdminPurgePost } from "./types/AdminPurgePost";
export { AdminPurgePostView } from "./types/AdminPurgePostView";
export { ApproveRegistrationApplication } from "./types/ApproveRegistrationApplication";
export { AuthenticateWithOauth } from "./types/AuthenticateWithOauth";
export { BanFromCommunity } from "./types/BanFromCommunity";
export { BanFromCommunityResponse } from "./types/BanFromCommunityResponse";
export { BanPerson } from "./types/BanPerson";
@ -42,7 +43,6 @@ export { CommentSortType } from "./types/CommentSortType";
export { CommentView } from "./types/CommentView";
export { Community } from "./types/Community";
export { CommunityAggregates } from "./types/CommunityAggregates";
export { CommunityBlockView } from "./types/CommunityBlockView";
export { CommunityFollowerView } from "./types/CommunityFollowerView";
export { CommunityId } from "./types/CommunityId";
export { CommunityModeratorView } from "./types/CommunityModeratorView";
@ -54,6 +54,7 @@ export { CreateCommentLike } from "./types/CreateCommentLike";
export { CreateCommentReport } from "./types/CreateCommentReport";
export { CreateCommunity } from "./types/CreateCommunity";
export { CreateCustomEmoji } from "./types/CreateCustomEmoji";
export { CreateOAuthProvider } from "./types/CreateOAuthProvider";
export { CreatePost } from "./types/CreatePost";
export { CreatePostLike } from "./types/CreatePostLike";
export { CreatePostReport } from "./types/CreatePostReport";
@ -69,12 +70,14 @@ export { DeleteAccount } from "./types/DeleteAccount";
export { DeleteComment } from "./types/DeleteComment";
export { DeleteCommunity } from "./types/DeleteCommunity";
export { DeleteCustomEmoji } from "./types/DeleteCustomEmoji";
export { DeleteOAuthProvider } from "./types/DeleteOAuthProvider";
export { DeletePost } from "./types/DeletePost";
export { DeletePrivateMessage } from "./types/DeletePrivateMessage";
export { DistinguishComment } from "./types/DistinguishComment";
export { EditComment } from "./types/EditComment";
export { EditCommunity } from "./types/EditCommunity";
export { EditCustomEmoji } from "./types/EditCustomEmoji";
export { EditOAuthProvider } from "./types/EditOAuthProvider";
export { EditPost } from "./types/EditPost";
export { EditPrivateMessage } from "./types/EditPrivateMessage";
export { EditSite } from "./types/EditSite";
@ -114,7 +117,6 @@ export { HideCommunity } from "./types/HideCommunity";
export { HidePost } from "./types/HidePost";
export { ImageDetails } from "./types/ImageDetails";
export { Instance } from "./types/Instance";
export { InstanceBlockView } from "./types/InstanceBlockView";
export { InstanceId } from "./types/InstanceId";
export { InstanceWithFederationState } from "./types/InstanceWithFederationState";
export { Language } from "./types/Language";
@ -127,6 +129,7 @@ export { ListCommentReports } from "./types/ListCommentReports";
export { ListCommentReportsResponse } from "./types/ListCommentReportsResponse";
export { ListCommunities } from "./types/ListCommunities";
export { ListCommunitiesResponse } from "./types/ListCommunitiesResponse";
export { ListLoginsResponse } from "./types/ListLoginsResponse";
export { ListMedia } from "./types/ListMedia";
export { ListMediaResponse } from "./types/ListMediaResponse";
export { ListPostLikes } from "./types/ListPostLikes";
@ -181,13 +184,17 @@ export { ModTransferCommunityView } from "./types/ModTransferCommunityView";
export { ModlogActionType } from "./types/ModlogActionType";
export { ModlogListParams } from "./types/ModlogListParams";
export { MyUserInfo } from "./types/MyUserInfo";
export { OAuthAccount } from "./types/OAuthAccount";
export { OAuthProvider } from "./types/OAuthProvider";
export { OAuthProviderId } from "./types/OAuthProviderId";
export { OAuthProviderInsertForm } from "./types/OAuthProviderInsertForm";
export { OAuthProviderUpdateForm } from "./types/OAuthProviderUpdateForm";
export { OpenGraphData } from "./types/OpenGraphData";
export { PaginationCursor } from "./types/PaginationCursor";
export { PasswordChangeAfterReset } from "./types/PasswordChangeAfterReset";
export { PasswordReset } from "./types/PasswordReset";
export { Person } from "./types/Person";
export { PersonAggregates } from "./types/PersonAggregates";
export { PersonBlockView } from "./types/PersonBlockView";
export { PersonId } from "./types/PersonId";
export { PersonMention } from "./types/PersonMention";
export { PersonMentionId } from "./types/PersonMentionId";
@ -214,6 +221,7 @@ export { PrivateMessageReportView } from "./types/PrivateMessageReportView";
export { PrivateMessageResponse } from "./types/PrivateMessageResponse";
export { PrivateMessageView } from "./types/PrivateMessageView";
export { PrivateMessagesResponse } from "./types/PrivateMessagesResponse";
export { PublicOAuthProvider } from "./types/PublicOAuthProvider";
export { PurgeComment } from "./types/PurgeComment";
export { PurgeCommunity } from "./types/PurgeCommunity";
export { PurgePerson } from "./types/PurgePerson";

View file

@ -0,0 +1,10 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export interface AuthenticateWithOauth {
code: string;
oauth_provider_id: string;
redirect_uri: string;
show_nsfw?: boolean;
username?: string;
answer?: string;
}

View file

@ -1,8 +0,0 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Community } from "./Community";
import type { Person } from "./Person";
export interface CommunityBlockView {
person: Person;
community: Community;
}

View file

@ -0,0 +1,16 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export interface CreateOAuthProvider {
display_name: string;
issuer: string;
authorization_endpoint: string;
token_endpoint: string;
userinfo_endpoint: string;
id_claim: string;
client_id: string;
client_secret: string;
scopes: string;
auto_verify_email: boolean;
account_linking_enabled: boolean;
enabled: boolean;
}

View file

@ -46,6 +46,7 @@ export interface CreateSite {
blocked_instances?: Array<string>;
taglines?: Array<string>;
registration_mode?: RegistrationMode;
oauth_registration?: boolean;
content_warning?: string;
default_post_listing_mode?: PostListingMode;
}

View file

@ -0,0 +1,6 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { OAuthProviderId } from "./OAuthProviderId";
export interface DeleteOAuthProvider {
id: OAuthProviderId;
}

View file

@ -0,0 +1,16 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { OAuthProviderId } from "./OAuthProviderId";
export interface EditOAuthProvider {
id: OAuthProviderId;
display_name: string | null;
authorization_endpoint: string | null;
token_endpoint: string | null;
userinfo_endpoint: string | null;
id_claim: string | null;
client_secret: string | null;
scopes: string | null;
auto_verify_email: boolean | null;
account_linking_enabled: boolean | null;
enabled: boolean | null;
}

View file

@ -47,6 +47,7 @@ export interface EditSite {
blocked_urls?: Array<string>;
taglines?: Array<string>;
registration_mode?: RegistrationMode;
oauth_registration?: boolean;
reports_email_admins?: boolean;
content_warning?: string;
default_post_listing_mode?: PostListingMode;

View file

@ -4,7 +4,9 @@ import type { Language } from "./Language";
import type { LanguageId } from "./LanguageId";
import type { LocalSiteUrlBlocklist } from "./LocalSiteUrlBlocklist";
import type { MyUserInfo } from "./MyUserInfo";
import type { OAuthProvider } from "./OAuthProvider";
import type { PersonView } from "./PersonView";
import type { PublicOAuthProvider } from "./PublicOAuthProvider";
import type { SiteView } from "./SiteView";
import type { Tagline } from "./Tagline";
@ -17,5 +19,7 @@ export interface GetSiteResponse {
discussion_languages: Array<LanguageId>;
taglines: Array<Tagline>;
custom_emojis: Array<CustomEmojiView>;
oauth_providers?: Array<PublicOAuthProvider>;
admin_oauth_providers?: Array<OAuthProvider>;
blocked_urls: Array<LocalSiteUrlBlocklist>;
}

View file

@ -1,10 +0,0 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Instance } from "./Instance";
import type { Person } from "./Person";
import type { Site } from "./Site";
export interface InstanceBlockView {
person: Person;
instance: Instance;
site?: Site;
}

View file

@ -46,6 +46,7 @@ export type LemmyErrorType =
| { error: "couldnt_find_comment_reply" }
| { error: "couldnt_find_private_message" }
| { error: "couldnt_find_activity" }
| { error: "couldnt_find_oauth_provider" }
| { error: "person_is_blocked" }
| { error: "community_is_blocked" }
| { error: "instance_is_blocked" }
@ -73,7 +74,9 @@ export type LemmyErrorType =
| { error: "invalid_default_post_listing_type" }
| { error: "registration_closed" }
| { error: "registration_application_answer_required" }
| { error: "registration_username_required" }
| { error: "email_already_exists" }
| { error: "username_already_exists" }
| { error: "federation_forbidden_by_strict_allow_list" }
| { error: "person_is_banned_from_community" }
| { error: "object_is_not_public" }
@ -166,5 +169,11 @@ export type LemmyErrorType =
| { error: "cant_block_local_instance" }
| { error: "url_without_domain" }
| { error: "inbox_timeout" }
| { error: "oauth_authorization_invalid" }
| { error: "oauth_login_failed" }
| { error: "oauth_registration_closed" }
| { error: "couldnt_delete_oauth_provider" }
| { error: "unknown"; message: string }
| { error: "cant_delete_site" }
| { error: "url_length_overflow" }
| { error: "cant_delete_site" };

View file

@ -0,0 +1,6 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { LoginToken } from "./LoginToken";
export interface ListLoginsResponse {
logins: Array<LoginToken>;
}

View file

@ -11,7 +11,6 @@ export interface LocalSite {
site_id: SiteId;
site_setup: boolean;
enable_downvotes: boolean;
enable_nsfw: boolean;
community_creation_admin_only: boolean;
require_email_verification: boolean;
application_question?: string;
@ -33,4 +32,5 @@ export interface LocalSite {
federation_signed_fetch: boolean;
default_post_listing_mode: PostListingMode;
default_sort_type: SortType;
oauth_registration: boolean;
}

View file

@ -16,7 +16,6 @@ export interface LocalUser {
interface_language: string;
show_avatars: boolean;
send_notifications_to_email: boolean;
show_scores: boolean;
show_bot_accounts: boolean;
show_read_posts: boolean;
email_verified: boolean;

View file

@ -1,8 +1,6 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { LocalUserId } from "./LocalUserId";
export interface LocalUserVoteDisplayMode {
local_user_id: LocalUserId;
score: boolean;
upvotes: boolean;
downvotes: boolean;

View file

@ -1,18 +1,18 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { CommunityBlockView } from "./CommunityBlockView";
import type { Community } from "./Community";
import type { CommunityFollowerView } from "./CommunityFollowerView";
import type { CommunityModeratorView } from "./CommunityModeratorView";
import type { InstanceBlockView } from "./InstanceBlockView";
import type { Instance } from "./Instance";
import type { LanguageId } from "./LanguageId";
import type { LocalUserView } from "./LocalUserView";
import type { PersonBlockView } from "./PersonBlockView";
import type { Person } from "./Person";
export interface MyUserInfo {
local_user_view: LocalUserView;
follows: Array<CommunityFollowerView>;
moderates: Array<CommunityModeratorView>;
community_blocks: Array<CommunityBlockView>;
instance_blocks: Array<InstanceBlockView>;
person_blocks: Array<PersonBlockView>;
community_blocks: Array<Community>;
instance_blocks: Array<Instance>;
person_blocks: Array<Person>;
discussion_languages: Array<LanguageId>;
}

11
src/types/OAuthAccount.ts Normal file
View file

@ -0,0 +1,11 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { LocalUserId } from "./LocalUserId";
import type { OAuthProviderId } from "./OAuthProviderId";
export interface OAuthAccount {
local_user_id: LocalUserId;
oauth_provider_id: OAuthProviderId;
oauth_user_id: string;
published: string;
updated?: string;
}

View file

@ -0,0 +1,19 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { OAuthProviderId } from "./OAuthProviderId";
export interface OAuthProvider {
id: OAuthProviderId;
display_name: string;
issuer: string;
authorization_endpoint: string;
token_endpoint: string;
userinfo_endpoint: string;
id_claim: string;
client_id: string;
scopes: string;
auto_verify_email: boolean;
account_linking_enabled: boolean;
enabled: boolean;
published: string;
updated?: string;
}

View file

@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export type OAuthProviderId = number;

View file

@ -0,0 +1,16 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export interface OAuthProviderInsertForm {
display_name: string;
issuer: string;
authorization_endpoint: string;
token_endpoint: string;
userinfo_endpoint: string;
id_claim: string;
client_id: string;
client_secret: string;
scopes: string;
auto_verify_email: boolean;
account_linking_enabled: boolean;
enabled: boolean;
}

View file

@ -0,0 +1,15 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export interface OAuthProviderUpdateForm {
display_name: string | null;
authorization_endpoint: string;
token_endpoint: string;
userinfo_endpoint: string;
id_claim: string | null;
client_secret: string | null;
scopes: string | null;
auto_verify_email: boolean | null;
account_linking_enabled: boolean | null;
enabled: boolean | null;
updated: string | null | null;
}

View file

@ -1,7 +0,0 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Person } from "./Person";
export interface PersonBlockView {
person: Person;
target: Person;
}

View file

@ -0,0 +1,4 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { OAuthProvider } from "./OAuthProvider";
export type PublicOAuthProvider = OAuthProvider;

View file

@ -15,4 +15,5 @@ export interface Search {
listing_type?: ListingType;
page?: number;
limit?: number;
post_title_only?: boolean;
}