]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/core/auth/auth.service.ts
Allow users/visitors to search through an account's videos (#3589)
[github/Chocobozzz/PeerTube.git] / client / src / app / core / auth / auth.service.ts
index 224f35f82008711b846a23d5b7c5a58a0648b32f..cdf13186b68f3338dc49ba687f0eed411c1bf0f8 100644 (file)
@@ -11,7 +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'
+import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
 
 interface UserLoginWithUsername extends UserLogin {
   access_token: string
@@ -27,7 +27,6 @@ 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',
@@ -43,7 +42,6 @@ export class AuthService {
   private loginChanged: Subject<AuthStatus>
   private user: AuthUser = null
   private refreshingTokenObservable: Observable<any>
-  private scopedTokens: ScopedToken
 
   constructor (
     private http: HttpClient,
@@ -97,7 +95,7 @@ export class AuthService {
           error => {
             let errorMessage = error.message
 
-            if (error.status === 403) {
+            if (error.status === HttpStatusCode.FORBIDDEN_403) {
               errorMessage = $localize`Cannot retrieve OAuth Client credentials: ${error.text}.
 Ensure you have correctly configured PeerTube (config/ directory), in particular the "webserver" section.`
             }
@@ -247,48 +245,6 @@ Ensure you have correctly configured PeerTube (config/ directory), in particular
         )
   }
 
-  getScopedTokens (): Promise<ScopedToken> {
-    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<ScopedToken>(AuthService.BASE_SCOPED_TOKENS_URL, { headers })
-              .subscribe(
-                scopedTokens => {
-                  this.scopedTokens = scopedTokens
-                  res(this.scopedTokens)
-                },
-
-                err => {
-                  console.error(err)
-                  rej(err)
-                }
-              )
-    })
-  }
-
-  renewScopedTokens (): Promise<ScopedToken> {
-    return new Promise((res, rej) => {
-      const authHeaderValue = this.getRequestHeaderValue()
-      const headers = new HttpHeaders().set('Authorization', authHeaderValue)
-
-      this.http.post<ScopedToken>(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<UserLoginWithUserInformation> {
     // User is not loaded yet, set manually auth header
     const headers = new HttpHeaders().set('Authorization', `${obj.token_type} ${obj.access_token}`)