added pixelfed Oauth compatibility

This commit is contained in:
Nicolas Constant 2019-09-27 21:55:40 -04:00
parent 252724aa7d
commit 8139a0ff72
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
2 changed files with 18 additions and 5 deletions

View File

@ -1,5 +1,5 @@
import { Injectable } from "@angular/core"; 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 { ApiRoutes } from './models/api.settings';
import { AppData, TokenData } from "./models/mastodon.interfaces"; 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<TokenData> { getToken(instance: string, client_id: string, client_secret: string, code: string, redirect_uri: string): Promise<TokenData> {
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<TokenData>(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<TokenData>(url, bodyLoad).toPromise();
} }
createNewApplication(instance: string, appName: string, redirectUrl: string, scopes: string, website: string): Promise<AppData> { createNewApplication(instance: string, appName: string, redirectUrl: string, scopes: string, website: string): Promise<AppData> {
const url = 'https://' + instance + this.apiRoutes.createApp; const url = 'https://' + instance + this.apiRoutes.createApp;
const formData = new FormData();
const formData = new FormData();
formData.append('client_name', appName); formData.append('client_name', appName);
formData.append('redirect_uris', redirectUrl); formData.append('redirect_uris', redirectUrl);
formData.append('scopes', scopes); formData.append('scopes', scopes);

View File

@ -31,6 +31,8 @@ export class ToolsService {
type = InstanceType.GlitchSoc; type = InstanceType.GlitchSoc;
} else if (instance.version.toLowerCase().includes('+florence')) { } else if (instance.version.toLowerCase().includes('+florence')) {
type = InstanceType.Florence; type = InstanceType.Florence;
} else if (instance.version.toLowerCase().includes('pixelfed')) {
type = InstanceType.Pixelfed;
} }
var splittedVersion = instance.version.split('.'); var splittedVersion = instance.version.split('.');
@ -39,6 +41,7 @@ export class ToolsService {
var instanceInfo = new InstanceInfo(type, major, minor); var instanceInfo = new InstanceInfo(type, major, minor);
this.instanceInfos[acc.instance] = instanceInfo; this.instanceInfos[acc.instance] = instanceInfo;
return instanceInfo; return instanceInfo;
}); });
} }
@ -171,5 +174,6 @@ export enum InstanceType {
Mastodon = 1, Mastodon = 1,
Pleroma = 2, Pleroma = 2,
GlitchSoc = 3, GlitchSoc = 3,
Florence = 4 Florence = 4,
Pixelfed = 5
} }