aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/core/auth
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-08-03 18:06:49 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-08-06 15:08:58 +0200
commit4504f09f6e85f09b0489debb547a17209d7176ea (patch)
tree1e2fdcdd3a0982f6e873205f69bdf90de7f4a883 /client/src/app/core/auth
parent71ab65d02f359000f9ca6a00f163d66d56a33955 (diff)
downloadPeerTube-4504f09f6e85f09b0489debb547a17209d7176ea.tar.gz
PeerTube-4504f09f6e85f09b0489debb547a17209d7176ea.tar.zst
PeerTube-4504f09f6e85f09b0489debb547a17209d7176ea.zip
deal with refresh token in embed
Diffstat (limited to 'client/src/app/core/auth')
-rw-r--r--client/src/app/core/auth/auth-user.model.ts63
-rw-r--r--client/src/app/core/auth/auth.service.ts2
2 files changed, 3 insertions, 62 deletions
diff --git a/client/src/app/core/auth/auth-user.model.ts b/client/src/app/core/auth/auth-user.model.ts
index 88b730938..ee61ff881 100644
--- a/client/src/app/core/auth/auth-user.model.ts
+++ b/client/src/app/core/auth/auth-user.model.ts
@@ -1,7 +1,7 @@
1import { Observable, of } from 'rxjs' 1import { Observable, of } from 'rxjs'
2import { map } from 'rxjs/operators' 2import { map } from 'rxjs/operators'
3import { User } from '@app/core/users/user.model' 3import { User } from '@app/core/users/user.model'
4import { peertubeLocalStorage } from '@app/helpers/peertube-web-storage' 4import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage'
5import { 5import {
6 hasUserRight, 6 hasUserRight,
7 MyUser as ServerMyUserModel, 7 MyUser as ServerMyUserModel,
@@ -12,66 +12,7 @@ import {
12 UserRole, 12 UserRole,
13 UserVideoQuota 13 UserVideoQuota
14} from '@shared/models' 14} from '@shared/models'
15 15import { TokenOptions, Tokens } from '../../../root-helpers/pure-auth-user.model'
16export type TokenOptions = {
17 accessToken: string
18 refreshToken: string
19 tokenType: string
20}
21
22// Private class only used by User
23class Tokens {
24 private static KEYS = {
25 ACCESS_TOKEN: 'access_token',
26 REFRESH_TOKEN: 'refresh_token',
27 TOKEN_TYPE: 'token_type'
28 }
29
30 accessToken: string
31 refreshToken: string
32 tokenType: string
33
34 static load () {
35 const accessTokenLocalStorage = peertubeLocalStorage.getItem(this.KEYS.ACCESS_TOKEN)
36 const refreshTokenLocalStorage = peertubeLocalStorage.getItem(this.KEYS.REFRESH_TOKEN)
37 const tokenTypeLocalStorage = peertubeLocalStorage.getItem(this.KEYS.TOKEN_TYPE)
38
39 if (accessTokenLocalStorage && refreshTokenLocalStorage && tokenTypeLocalStorage) {
40 return new Tokens({
41 accessToken: accessTokenLocalStorage,
42 refreshToken: refreshTokenLocalStorage,
43 tokenType: tokenTypeLocalStorage
44 })
45 }
46
47 return null
48 }
49
50 static flush () {
51 peertubeLocalStorage.removeItem(this.KEYS.ACCESS_TOKEN)
52 peertubeLocalStorage.removeItem(this.KEYS.REFRESH_TOKEN)
53 peertubeLocalStorage.removeItem(this.KEYS.TOKEN_TYPE)
54 }
55
56 constructor (hash?: TokenOptions) {
57 if (hash) {
58 this.accessToken = hash.accessToken
59 this.refreshToken = hash.refreshToken
60
61 if (hash.tokenType === 'bearer') {
62 this.tokenType = 'Bearer'
63 } else {
64 this.tokenType = hash.tokenType
65 }
66 }
67 }
68
69 save () {
70 peertubeLocalStorage.setItem(Tokens.KEYS.ACCESS_TOKEN, this.accessToken)
71 peertubeLocalStorage.setItem(Tokens.KEYS.REFRESH_TOKEN, this.refreshToken)
72 peertubeLocalStorage.setItem(Tokens.KEYS.TOKEN_TYPE, this.tokenType)
73 }
74}
75 16
76export class AuthUser extends User implements ServerMyUserModel { 17export class AuthUser extends User implements ServerMyUserModel {
77 tokens: Tokens 18 tokens: Tokens
diff --git a/client/src/app/core/auth/auth.service.ts b/client/src/app/core/auth/auth.service.ts
index 94262b9aa..d3dc48267 100644
--- a/client/src/app/core/auth/auth.service.ts
+++ b/client/src/app/core/auth/auth.service.ts
@@ -5,7 +5,7 @@ import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'
5import { Injectable } from '@angular/core' 5import { Injectable } from '@angular/core'
6import { Router } from '@angular/router' 6import { Router } from '@angular/router'
7import { Notifier } from '@app/core/notification/notifier.service' 7import { Notifier } from '@app/core/notification/notifier.service'
8import { objectToUrlEncoded, peertubeLocalStorage } from '@app/helpers' 8import { objectToUrlEncoded, peertubeLocalStorage } from '@root-helpers/index'
9import { I18n } from '@ngx-translate/i18n-polyfill' 9import { I18n } from '@ngx-translate/i18n-polyfill'
10import { MyUser as UserServerModel, OAuthClientLocal, User, UserLogin, UserRefreshToken } from '@shared/models' 10import { MyUser as UserServerModel, OAuthClientLocal, User, UserLogin, UserRefreshToken } from '@shared/models'
11import { environment } from '../../../environments/environment' 11import { environment } from '../../../environments/environment'