From afff310e50f2fa8419bb4242470cbde46ab54463 Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Thu, 13 Aug 2020 15:07:23 +0200 Subject: allow private syndication feeds via a user feedToken --- client/src/app/core/auth/auth.service.ts | 45 ++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'client/src/app/core/auth') diff --git a/client/src/app/core/auth/auth.service.ts b/client/src/app/core/auth/auth.service.ts index fd6062d3f..224f35f82 100644 --- a/client/src/app/core/auth/auth.service.ts +++ b/client/src/app/core/auth/auth.service.ts @@ -11,6 +11,7 @@ import { environment } from '../../../environments/environment' import { RestExtractor } from '../rest/rest-extractor.service' import { AuthStatus } from './auth-status.model' import { AuthUser } from './auth-user.model' +import { ScopedTokenType, ScopedToken } from '@shared/models/users/user-scoped-token' interface UserLoginWithUsername extends UserLogin { access_token: string @@ -26,6 +27,7 @@ export class AuthService { private static BASE_CLIENT_URL = environment.apiUrl + '/api/v1/oauth-clients/local' private static BASE_TOKEN_URL = environment.apiUrl + '/api/v1/users/token' private static BASE_REVOKE_TOKEN_URL = environment.apiUrl + '/api/v1/users/revoke-token' + private static BASE_SCOPED_TOKENS_URL = environment.apiUrl + '/api/v1/users/scoped-tokens' private static BASE_USER_INFORMATION_URL = environment.apiUrl + '/api/v1/users/me' private static LOCAL_STORAGE_OAUTH_CLIENT_KEYS = { CLIENT_ID: 'client_id', @@ -41,6 +43,7 @@ export class AuthService { private loginChanged: Subject private user: AuthUser = null private refreshingTokenObservable: Observable + private scopedTokens: ScopedToken constructor ( private http: HttpClient, @@ -244,6 +247,48 @@ Ensure you have correctly configured PeerTube (config/ directory), in particular ) } + getScopedTokens (): Promise { + return new Promise((res, rej) => { + if (this.scopedTokens) return res(this.scopedTokens) + + const authHeaderValue = this.getRequestHeaderValue() + const headers = new HttpHeaders().set('Authorization', authHeaderValue) + + this.http.get(AuthService.BASE_SCOPED_TOKENS_URL, { headers }) + .subscribe( + scopedTokens => { + this.scopedTokens = scopedTokens + res(this.scopedTokens) + }, + + err => { + console.error(err) + rej(err) + } + ) + }) + } + + renewScopedTokens (): Promise { + return new Promise((res, rej) => { + const authHeaderValue = this.getRequestHeaderValue() + const headers = new HttpHeaders().set('Authorization', authHeaderValue) + + this.http.post(AuthService.BASE_SCOPED_TOKENS_URL, {}, { headers }) + .subscribe( + scopedTokens => { + this.scopedTokens = scopedTokens + res(this.scopedTokens) + }, + + err => { + console.error(err) + rej(err) + } + ) + }) + } + private mergeUserInformation (obj: UserLoginWithUsername): Observable { // User is not loaded yet, set manually auth header const headers = new HttpHeaders().set('Authorization', `${obj.token_type} ${obj.access_token}`) -- cgit v1.2.3