Merge pull request #174 from NicolasConstant/topic_pixelfed-compatibility
added pixelfed Oauth compatibility
This commit is contained in:
commit
e5aea3c4a6
|
@ -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<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> {
|
||||
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);
|
||||
|
|
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue