From 8139a0ff7230fbdbea8909ae00aa280a4c8e5829 Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Fri, 27 Sep 2019 21:55:40 -0400 Subject: [PATCH] added pixelfed Oauth compatibility --- src/app/services/auth.service.ts | 17 +++++++++++++---- src/app/services/tools.service.ts | 6 +++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index ec4f684a..1815696d 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -1,5 +1,5 @@ import { Injectable } from "@angular/core"; -import { HttpClient } from "@angular/common/http"; +import { HttpClient, HttpHeaders } from "@angular/common/http"; import { ApiRoutes } from './models/api.settings'; import { AppData, TokenData } from "./models/mastodon.interfaces"; @@ -17,15 +17,24 @@ export class AuthService { } getToken(instance: string, client_id: string, client_secret: string, code: string, redirect_uri: string): Promise { - const url = `https://${instance}/oauth/token?client_id=${client_id}&client_secret=${client_secret}&grant_type=authorization_code&code=${code}&redirect_uri=${encodeURIComponent(redirect_uri)}`; + const encodedRedirectUri = encodeURIComponent(redirect_uri); + const url = `https://${instance}/oauth/token?client_id=${client_id}&client_secret=${client_secret}&grant_type=authorization_code&code=${code}&redirect_uri=${encodedRedirectUri}`; - return this.httpClient.post(url, null).toPromise(); + const bodyLoad = { + 'client_id': client_id, + 'client_secret': client_secret, + 'grant_type': 'authorization_code', + 'redirect_uri': redirect_uri, + 'code': code + }; + + return this.httpClient.post(url, bodyLoad).toPromise(); } createNewApplication(instance: string, appName: string, redirectUrl: string, scopes: string, website: string): Promise { const url = 'https://' + instance + this.apiRoutes.createApp; - const formData = new FormData(); + const formData = new FormData(); formData.append('client_name', appName); formData.append('redirect_uris', redirectUrl); formData.append('scopes', scopes); diff --git a/src/app/services/tools.service.ts b/src/app/services/tools.service.ts index 356603c6..5ad49485 100644 --- a/src/app/services/tools.service.ts +++ b/src/app/services/tools.service.ts @@ -31,6 +31,8 @@ export class ToolsService { type = InstanceType.GlitchSoc; } else if (instance.version.toLowerCase().includes('+florence')) { type = InstanceType.Florence; + } else if (instance.version.toLowerCase().includes('pixelfed')) { + type = InstanceType.Pixelfed; } var splittedVersion = instance.version.split('.'); @@ -39,6 +41,7 @@ export class ToolsService { var instanceInfo = new InstanceInfo(type, major, minor); this.instanceInfos[acc.instance] = instanceInfo; + return instanceInfo; }); } @@ -171,5 +174,6 @@ export enum InstanceType { Mastodon = 1, Pleroma = 2, GlitchSoc = 3, - Florence = 4 + Florence = 4, + Pixelfed = 5 } \ No newline at end of file