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

SSO Support #297

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions copy_generated_types_from_lemmy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
57 changes: 57 additions & 0 deletions src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
Expand Down Expand Up @@ -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";

enum HttpType {
Get = "GET",
Expand Down Expand Up @@ -1421,6 +1426,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.
*
Expand Down
12 changes: 11 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -54,6 +55,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";
Expand All @@ -69,12 +71,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";
Expand Down Expand Up @@ -111,6 +115,7 @@ export { GetUnreadCountResponse } from "./types/GetUnreadCountResponse";
export { GetUnreadRegistrationApplicationCountResponse } from "./types/GetUnreadRegistrationApplicationCountResponse";
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";
Expand Down Expand Up @@ -179,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 { PersonBlockId } from "./types/PersonBlockId";
export { PersonBlockView } from "./types/PersonBlockView";
export { PersonId } from "./types/PersonId";
export { PersonMention } from "./types/PersonMention";
Expand Down Expand Up @@ -213,6 +222,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";
Expand Down
10 changes: 10 additions & 0 deletions src/types/AuthenticateWithOauth.ts
Original file line number Diff line number Diff line change
@@ -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;
}
16 changes: 16 additions & 0 deletions src/types/CreateOAuthProvider.ts
Original file line number Diff line number Diff line change
@@ -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;
}
1 change: 1 addition & 0 deletions src/types/CreateSite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
6 changes: 6 additions & 0 deletions src/types/DeleteOAuthProvider.ts
Original file line number Diff line number Diff line change
@@ -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;
}
16 changes: 16 additions & 0 deletions src/types/EditOAuthProvider.ts
Original file line number Diff line number Diff line change
@@ -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;
}
1 change: 1 addition & 0 deletions src/types/EditSite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/types/GetPosts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ export interface GetPosts {
liked_only?: boolean;
disliked_only?: boolean;
show_hidden?: boolean;
show_read?: boolean;
show_nsfw?: boolean;
page_cursor?: PaginationCursor;
}
4 changes: 4 additions & 0 deletions src/types/GetSiteResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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>;
}
8 changes: 8 additions & 0 deletions src/types/ImageDetails.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export interface ImageDetails {
link: string;
width: number;
height: number;
content_type: string;
}
7 changes: 7 additions & 0 deletions src/types/LemmyErrorType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,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" }
Expand Down Expand Up @@ -71,7 +72,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" }
Expand Down Expand Up @@ -164,4 +167,8 @@ 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 };
1 change: 1 addition & 0 deletions src/types/LocalSite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ export interface LocalSite {
federation_signed_fetch: boolean;
default_post_listing_mode: PostListingMode;
default_sort_type: SortType;
oauth_registration: boolean;
}
11 changes: 11 additions & 0 deletions src/types/OAuthAccount.ts
Original file line number Diff line number Diff line change
@@ -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;
}
19 changes: 19 additions & 0 deletions src/types/OAuthProvider.ts
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export type PersonBlockId = number;
export type OAuthProviderId = number;
16 changes: 16 additions & 0 deletions src/types/OAuthProviderInsertForm.ts
Original file line number Diff line number Diff line change
@@ -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;
}
15 changes: 15 additions & 0 deletions src/types/OAuthProviderUpdateForm.ts
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 2 additions & 0 deletions src/types/PostView.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// 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 { ImageDetails } from "./ImageDetails";
import type { Person } from "./Person";
import type { Post } from "./Post";
import type { PostAggregates } from "./PostAggregates";
Expand All @@ -9,6 +10,7 @@ export interface PostView {
post: Post;
creator: Person;
community: Community;
image_details?: ImageDetails;
creator_banned_from_community: boolean;
banned_from_community: boolean;
creator_is_moderator: boolean;
Expand Down
4 changes: 4 additions & 0 deletions src/types/PublicOAuthProvider.ts
Original file line number Diff line number Diff line change
@@ -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;