clean up
This commit is contained in:
parent
be6211a04b
commit
6c96ec694c
|
@ -59,9 +59,6 @@ export class RegisterNewAccountComponent implements OnInit {
|
|||
console.error('registeredApps$')
|
||||
console.warn(x);
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
onSubmit(): boolean {
|
||||
|
@ -69,27 +66,38 @@ export class RegisterNewAccountComponent implements OnInit {
|
|||
|
||||
const username = fullHandle[0];
|
||||
const instance = fullHandle[1];
|
||||
console.log(`username ${username} instance ${instance}`);
|
||||
|
||||
const redirect_uri = this.getLocalHostname() + '/register';
|
||||
|
||||
let localUrl = location.protocol + '//' + location.hostname + (location.port ? ':' + location.port : '');
|
||||
|
||||
if (localUrl === 'file://') {
|
||||
localUrl = 'http://localhost:4200';
|
||||
}
|
||||
const redirect_uri = localUrl + '/register';
|
||||
|
||||
this.authService.createNewApplication(instance, redirect_uri)
|
||||
this.authService.createNewApplication(instance, 'Sengi', redirect_uri, 'read write follow', 'https://github.com/NicolasConstant/sengi')
|
||||
.then((appData: AppData) => {
|
||||
|
||||
const appDataTemp = new AppDataWrapper(username, instance, appData);
|
||||
localStorage.setItem('tempAuth', JSON.stringify(appDataTemp));
|
||||
|
||||
let instanceUrl = `https://${instance}/oauth/authorize?scope=${encodeURIComponent('read write follow')}&response_type=code&redirect_uri=${encodeURIComponent(redirect_uri)}&client_id=${appData.client_id}`;
|
||||
|
||||
window.location.href = instanceUrl;
|
||||
this.processAndRedirectToAuthPage(username, instance, appData);
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
private getLocalHostname(): string {
|
||||
let localHostname = location.protocol + '//' + location.hostname + (location.port ? ':' + location.port : '');
|
||||
|
||||
//Electron hack
|
||||
if (localHostname === 'file://') {
|
||||
localHostname = 'http://localhost:4200';
|
||||
}
|
||||
|
||||
return localHostname;
|
||||
}
|
||||
|
||||
private processAndRedirectToAuthPage(username: string, instance: string, app: AppData){
|
||||
const appDataTemp = new AppDataWrapper(username, instance, app);
|
||||
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}`;
|
||||
|
||||
window.location.href = instanceUrl;
|
||||
}
|
||||
}
|
||||
|
||||
class AppDataWrapper {
|
||||
|
|
|
@ -17,15 +17,15 @@ export class AuthService {
|
|||
return this.httpClient.post<TokenData>(url, null).toPromise();
|
||||
}
|
||||
|
||||
createNewApplication(instance: string, redirectUrl: string): Promise<AppData> {
|
||||
const url = 'https://' + instance + this.apiRoutes.createApp;
|
||||
createNewApplication(instance: string, appName: string, redirectUrl: string, scopes: string, website: string): Promise<AppData> {
|
||||
const url = 'https://' + instance + this.apiRoutes.createApp;
|
||||
const formData = new FormData();
|
||||
|
||||
formData.append('client_name', 'Sengi');
|
||||
formData.append('client_name', appName);
|
||||
formData.append('redirect_uris', redirectUrl);
|
||||
formData.append('scopes', 'read write follow');
|
||||
formData.append('website', 'https://github.com/NicolasConstant/sengi');
|
||||
formData.append('scopes', scopes);
|
||||
formData.append('website', website);
|
||||
|
||||
return this.httpClient.post<AppData>(url, formData).toPromise();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue