This commit is contained in:
Nicolas Constant 2018-09-07 23:34:17 -04:00
parent aa248c69b3
commit 5ac403b430
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
3 changed files with 5 additions and 72 deletions

View File

@ -46,7 +46,7 @@ export class RegisterNewAccountComponent implements OnInit {
localStorage.removeItem('tempAuth');
//TODO review all this
this.accountsService.addNewAccount(appDataWrapper.instance, appDataWrapper.username, tokenData);
// this.accountsService.addNewAccount(appDataWrapper.instance, appDataWrapper.username, tokenData);
});

View File

@ -1,34 +1,17 @@
import { Injectable } from '@angular/core';
import { Http, Response, RequestOptions } from '@angular/http';
import { map } from "rxjs/operators";
import { ApiRoutes } from './models/api.settings';
import { AppData } from './models/mastodon.interfaces';
import { Router } from '@angular/router';
import { HttpClient } from '@angular/common/http';
@Injectable()
export class AppService {
private apiRoutes = new ApiRoutes();
constructor(
private readonly httpService: Http,
private readonly router: Router) {
constructor(private readonly httpClient: HttpClient) {
}
createNewApplication(instance: string, redirectUrl: string): Promise<AppData> {
const url = 'https://' + instance + this.apiRoutes.createApp;
// const redirect_uri = this.router.url;
// var redirect_uri = location.protocol+'//'+location.hostname+(location.port ? ':'+location.port: '');
// if(redirect_uri === 'file://'){
// redirect_uri = 'http://localhost';
// }
// console.warn(`redirect_uri ${redirect_uri}`);
// return null;
const options = new RequestOptions();
const url = 'https://' + instance + this.apiRoutes.createApp;
const formData = new FormData();
formData.append('client_name', 'Sengi');
@ -36,18 +19,6 @@ export class AppService {
formData.append('scopes', 'read write follow');
formData.append('website', 'https://github.com/NicolasConstant/sengi');
return this.httpService.post(url, formData, options)
.pipe(
map((res: Response) => {
const result = res.json();
console.warn(result);
return result as AppData;
}))
.toPromise();
// // .then((res: Response) => {
// // const result = res.json();
// // return result as TokenData;
// // });
return this.httpClient.post<AppData>(url, formData).toPromise();
}
}

View File

@ -1,51 +1,13 @@
import { Injectable } from "@angular/core";
import { Http, Response, RequestOptions } from "@angular/http";
import { ApiRoutes } from "./models/api.settings";
import { TokenData } from "./models/mastodon.interfaces";
import { HttpClient } from "@angular/common/http";
@Injectable()
export class AuthService {
private apiRoutes = new ApiRoutes();
constructor(
private readonly httpClient: HttpClient) {
}
// getToken(instance: string, email: string, password: string): Promise<TokenData> {
// //TODO retrieve those via API
// const clientId = localStorage.getItem("client_id");
// const clientSecret = localStorage.getItem("client_secret");
// //Retrieve Token
// const url = this.getHostUrl(instance) + this.apiRoutes.getToken;
// const options = new RequestOptions();
// const formData = new FormData();
// formData.append("client_id", clientId);
// formData.append("client_secret", clientSecret);
// formData.append("grant_type", "password");
// formData.append("username", email);
// formData.append("password", password);
// formData.append("scope", "read write follow");
// return this.httpService.post(url, formData, options).toPromise()
// .then((res: Response) => {
// const result = res.json();
// return result as TokenData;
// });
// }
// private getHostUrl(url: string): string {
// url = url.replace("http://", "");
// if (!url.startsWith("https://")) {
// url = "https://" + url;
// }
// return url;
// }
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)}`;