]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/core/auth/auth.service.ts
Update client dependencies
[github/Chocobozzz/PeerTube.git] / client / src / app / core / auth / auth.service.ts
index fcc6b9bb6430016812fb1cefa8e750582625238b..de9e14b2d7d4823e3fffeff0f08b9bf766548d24 100644 (file)
@@ -11,13 +11,13 @@ import { NotificationsService } from 'angular2-notifications'
 
 import { AuthStatus } from './auth-status.model'
 import { AuthUser } from './auth-user.model'
-import { ClientLocal } from '../../../../../shared'
+import { OAuthClientLocal, UserRole } from '../../../../../shared'
 // Do not use the barrel (dependency loop)
 import { RestExtractor } from '../../shared/rest'
 
 @Injectable()
 export class AuthService {
-  private static BASE_CLIENT_URL = API_URL + '/api/v1/clients/local'
+  private static BASE_CLIENT_URL = API_URL + '/api/v1/oauth-clients/local'
   private static BASE_TOKEN_URL = API_URL + '/api/v1/users/token'
   private static BASE_USER_INFORMATIONS_URL = API_URL + '/api/v1/users/me'
 
@@ -43,7 +43,7 @@ export class AuthService {
       .map(this.restExtractor.extractDataGet)
       .catch(res => this.restExtractor.handleError(res))
       .subscribe(
-        (result: ClientLocal) => {
+        (result: OAuthClientLocal) => {
           this.clientId = result.client_id
           this.clientSecret = result.client_secret
           console.log('Client credentials loaded.')
@@ -181,7 +181,10 @@ export class AuthService {
 
   refreshUserInformations () {
     const obj = {
-      access_token: this.user.getAccessToken()
+      access_token: this.user.getAccessToken(),
+      refresh_token: null,
+      token_type: this.user.getTokenType(),
+      username: this.user.username
     }
 
     this.mergeUserInformations (obj)
@@ -195,7 +198,12 @@ export class AuthService {
         )
   }
 
-  private mergeUserInformations (obj: { access_token: string }) {
+  private mergeUserInformations (obj: {
+    access_token: string,
+    refresh_token: string,
+    token_type: string,
+    username: string
+  }) {
     // Do not call authHttp here to avoid circular dependencies headaches
 
     const headers = new Headers()
@@ -205,9 +213,10 @@ export class AuthService {
              .map(res => res.json())
              .map(res => {
                const newProperties = {
-                 id: res.id,
-                 role: res.role,
-                 displayNSFW: res.displayNSFW
+                 id: res.id as number,
+                 role: res.role as UserRole,
+                 displayNSFW: res.displayNSFW as boolean,
+                 email: res.email as string
                }
 
                return Object.assign(obj, newProperties)
@@ -215,7 +224,16 @@ export class AuthService {
     )
   }
 
-  private handleLogin (obj: any) {
+  private handleLogin (obj: {
+    access_token: string,
+    refresh_token: string,
+    token_type: string,
+    id: number,
+    username: string,
+    email: string,
+    role: UserRole,
+    displayNSFW: boolean
+  }) {
     const id = obj.id
     const username = obj.username
     const role = obj.role
@@ -233,7 +251,7 @@ export class AuthService {
     this.setStatus(AuthStatus.LoggedIn)
   }
 
-  private handleRefreshToken (obj: any) {
+  private handleRefreshToken (obj: { access_token: string, refresh_token: string }) {
     this.user.refreshTokens(obj.access_token, obj.refresh_token)
     this.user.save()
   }