diff --git a/src/app/pages/register-new-account/register-new-account.component.ts b/src/app/pages/register-new-account/register-new-account.component.ts index ce8f31db..99864385 100644 --- a/src/app/pages/register-new-account/register-new-account.component.ts +++ b/src/app/pages/register-new-account/register-new-account.component.ts @@ -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; } diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index 2e4f9cb0..6f2bcf83 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -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 { 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)}`;