If you'd like to participate in this jam, feel free to log in!
+To log in with GitHub, enter "github.com"
-Tested on Mastodon, GoToSocial, Pleroma, and Misskey
+Tested on GitHub, Mastodon, GoToSocial, Pleroma, and Misskey
Enjoy!
To log in with GitHub, enter "github.com"
-Tested on Mastodon, GoToSocial, Pleroma, and Misskey
+Tested on GitHub, Mastodon, GoToSocial, Pleroma, and Misskey
Logged in as {existingUser?.username}@{existingUser?.instance} (Logout)
diff --git a/src/lib/mastoauth/mastoauth.ts b/src/lib/mastoauth/mastoauth.ts index b04a7c9..264c793 100644 --- a/src/lib/mastoauth/mastoauth.ts +++ b/src/lib/mastoauth/mastoauth.ts @@ -73,16 +73,28 @@ export class MastoAuth { formData.append('client_id', client.client_id); formData.append('client_secret', client.client_secret); formData.append('redirect_uri', client.redirect_uri); - formData.append('grant_type', 'authorization_code'); + if (this.instance != "github.com") + formData.append('grant_type', 'authorization_code'); formData.append('code', code); - formData.append('scope', 'read'); + if (this.instance != "github.com") + formData.append('scope', 'read'); let appRequest; - try { - appRequest = await fetch(`https://${this.instance}/oauth/token`, { - body: formData, - method: "post" - }); + try { + if (this.instance == "github.com") { + appRequest = await fetch(`https://${this.instance}/login/oauth/access_token`, { + body: formData, + method: "post", + headers: { + "Accept": "application/json" + } + }); + } else { + appRequest = await fetch(`https://${this.instance}/oauth/token`, { + body: formData, + method: "post" + }); + } } catch (err) { return null; } @@ -92,7 +104,7 @@ export class MastoAuth { access_token: string, token_type: string, scope: string, - created_at: number + created_at?: number } = await appRequest.json(); return reqEntities; } else return null; @@ -101,11 +113,19 @@ export class MastoAuth { async verifyUser(auth: string) { let appRequest; try { - appRequest = await fetch(`https://${this.instance}/api/v1/accounts/verify_credentials`, { - headers: { - "Authorization": auth - } - }); + if (this.instance == "github.com") { + appRequest = await fetch(`https://api.${this.instance}/user`, { + headers: { + "Authorization": auth + } + }); + } else { + appRequest = await fetch(`https://${this.instance}/api/v1/accounts/verify_credentials`, { + headers: { + "Authorization": auth + } + }); + } } catch (err) { return null; }