refactor: rewrite oauth login and 2fa for the new api
This commit is contained in:
@ -7,6 +7,7 @@ import {AvailableOAuthProvidersResponse} from "@api/v1/availableProvidersRespons
|
||||
import {OAuthProvider} from "@model/oAuthProvider";
|
||||
import {TwoFactorAuthentication} from "@model/twoFactorAuthentication";
|
||||
import {TwoFactorAuthRequest} from "@api/v1/twoFactorAuthRequest";
|
||||
import {OAuthAction} from "@model/oAuthAction";
|
||||
|
||||
export interface OAuthProviderData extends AvailableOAuthProvidersResponse {
|
||||
icon: string;
|
||||
@ -83,9 +84,10 @@ export default class AuthApiService extends ApiService {
|
||||
}
|
||||
}
|
||||
|
||||
public availableProviders(): Observable<OAuthProviderData[]> {
|
||||
public availableProviders(callback: string): Observable<OAuthProviderData[]> {
|
||||
let request = this.createRequestBuilder()
|
||||
.setEndpoint('AvailableProviders')
|
||||
.setQueryParams({callback: callback})
|
||||
.setWithCredentials()
|
||||
.build;
|
||||
|
||||
@ -97,4 +99,21 @@ export default class AuthApiService extends ApiService {
|
||||
}) as OAuthProviderData);
|
||||
}));
|
||||
}
|
||||
|
||||
private handleTokenRequest(token: string, action: OAuthAction) {
|
||||
return this.createRequestBuilder()
|
||||
.setEndpoint('HandleToken')
|
||||
.setQueryParams({token: token, action: action})
|
||||
.setWithCredentials()
|
||||
.build;
|
||||
}
|
||||
|
||||
public loginOAuth(token: string) {
|
||||
return this.get<TwoFactorAuthentication>(this.handleTokenRequest(token, OAuthAction.Login));
|
||||
}
|
||||
|
||||
public linkAccount(token: string): Observable<null> {
|
||||
const request = this.handleTokenRequest(token, OAuthAction.Bind);
|
||||
return this.addAuth(request).get(request);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user