refactoring to keep all auth data at the same place

This commit is contained in:
Nicolas Constant 2018-09-12 20:23:06 -04:00
parent 4639f0076f
commit bcf26ee1fc
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
2 changed files with 8 additions and 2 deletions

View File

@ -120,7 +120,8 @@ export class RegisterNewAccountComponent implements OnInit {
const appDataTemp = new CurrentAuthProcess(username, instance);
localStorage.setItem('tempAuth', JSON.stringify(appDataTemp));
let instanceUrl = `https://${instance}/oauth/authorize?scope=${encodeURIComponent('read write follow')}&response_type=code&redirect_uri=${encodeURIComponent(app.redirect_uri)}&client_id=${app.client_id}`;
let instanceUrl = this.authService.getInstanceLoginUrl(instance, app.client_id, app.redirect_uri);
// let instanceUrl = `https://${instance}/oauth/authorize?scope=${encodeURIComponent('read write follow')}&response_type=code&redirect_uri=${encodeURIComponent(app.redirect_uri)}&client_id=${app.client_id}`;
window.location.href = instanceUrl;
}

View File

@ -1,7 +1,8 @@
import { Injectable } from "@angular/core";
import { HttpClient } from "@angular/common/http";
import { ApiRoutes } from './models/api.settings';
import { AppData, TokenData } from "./models/mastodon.interfaces";
import { HttpClient } from "@angular/common/http";
@Injectable()
export class AuthService {
@ -11,6 +12,10 @@ export class AuthService {
private readonly httpClient: HttpClient) {
}
getInstanceLoginUrl(instance: string, client_id: string, redirect_uri: string): string{
return `https://${instance}/oauth/authorize?scope=${encodeURIComponent('read write follow')}&response_type=code&redirect_uri=${encodeURIComponent(redirect_uri)}&client_id=${client_id}`;
}
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)}`;