Skip to content

Commit

Permalink
deal with refresh token in embed
Browse files Browse the repository at this point in the history
  • Loading branch information
rigelk committed Aug 5, 2020
1 parent c8bc262 commit ede0baf
Show file tree
Hide file tree
Showing 25 changed files with 320 additions and 194 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BytesPipe } from 'ngx-pipes'
import { SortMeta } from 'primeng/api'
import { Component, OnInit } from '@angular/core'
import { ConfirmService, Notifier, RestPagination, RestTable, ServerService } from '@app/core'
import { peertubeLocalStorage } from '@app/helpers/peertube-web-storage'
import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage'
import { RedundancyService } from '@app/shared/shared-main'
import { I18n } from '@ngx-translate/i18n-polyfill'
import { VideoRedundanciesTarget, VideoRedundancy } from '@shared/models'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { DomSanitizer } from '@angular/platform-browser'
@Component({
selector: 'my-video-block-list',
templateUrl: './video-block-list.component.html',
styleUrls: [ '../../../shared/shared-moderation/moderation.scss', '../../../shared/shared-abuse-list/abuse-list-table.component.scss', './video-block-list.component.scss' ]
styleUrls: [ '../../../shared/shared-moderation/moderation.scss', './video-block-list.component.scss' ]
})
export class VideoBlockListComponent extends RestTable implements OnInit, AfterViewInit {
blocklist: (VideoBlacklist & { reasonHtml?: string, embedHtml?: string })[] = []
Expand Down
2 changes: 1 addition & 1 deletion client/src/app/+admin/system/jobs/jobs.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SortMeta } from 'primeng/api'
import { Component, OnInit } from '@angular/core'
import { Notifier, RestPagination, RestTable } from '@app/core'
import { peertubeLocalStorage } from '@app/helpers/peertube-web-storage'
import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage'
import { I18n } from '@ngx-translate/i18n-polyfill'
import { Job, JobState, JobType } from '@shared/models'
import { JobStateClient } from '../../../../types/job-state-client.type'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, Input } from '@angular/core'
import { Router } from '@angular/router'
import { AuthService, ComponentPagination, LocalStorageService, Notifier, SessionStorageService, UserService } from '@app/core'
import { peertubeLocalStorage, peertubeSessionStorage } from '@app/helpers/peertube-web-storage'
import { peertubeLocalStorage, peertubeSessionStorage } from '@root-helpers/peertube-web-storage'
import { VideoPlaylist, VideoPlaylistElement, VideoPlaylistService } from '@app/shared/shared-video-playlist'
import { I18n } from '@ngx-translate/i18n-polyfill'
import { VideoDetails, VideoPlaylistPrivacy } from '@shared/models'
Expand Down
3 changes: 2 additions & 1 deletion client/src/app/+videos/+video-watch/video-watch.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { ActivatedRoute, Router } from '@angular/router'
import { AuthService, AuthUser, ConfirmService, MarkdownService, Notifier, RestExtractor, ServerService, UserService } from '@app/core'
import { HooksService } from '@app/core/plugins/hooks.service'
import { RedirectService } from '@app/core/routing/redirect.service'
import { isXPercentInViewport, peertubeLocalStorage, scrollToTop } from '@app/helpers'
import { isXPercentInViewport, scrollToTop } from '@app/helpers'
import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage'
import { Video, VideoCaptionService, VideoDetails, VideoService } from '@app/shared/shared-main'
import { SubscribeButtonComponent } from '@app/shared/shared-user-subscription'
import { VideoPlaylist, VideoPlaylistService } from '@app/shared/shared-video-playlist'
Expand Down
3 changes: 2 additions & 1 deletion client/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
import { I18n } from '@ngx-translate/i18n-polyfill'
import { BroadcastMessageLevel, getShortLocale, is18nPath, ServerConfig, UserRole } from '@shared/models'
import { MenuService } from './core/menu/menu.service'
import { peertubeLocalStorage, POP_STATE_MODAL_DISMISS } from './helpers'
import { POP_STATE_MODAL_DISMISS } from './helpers'
import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage'
import { InstanceService } from './shared/shared-instance'

@Component({
Expand Down
63 changes: 2 additions & 61 deletions client/src/app/core/auth/auth-user.model.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Observable, of } from 'rxjs'
import { map } from 'rxjs/operators'
import { User } from '@app/core/users/user.model'
import { peertubeLocalStorage } from '@app/helpers/peertube-web-storage'
import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage'
import {
hasUserRight,
MyUser as ServerMyUserModel,
Expand All @@ -12,66 +12,7 @@ import {
UserRole,
UserVideoQuota
} from '@shared/models'

export type TokenOptions = {
accessToken: string
refreshToken: string
tokenType: string
}

// Private class only used by User
class Tokens {
private static KEYS = {
ACCESS_TOKEN: 'access_token',
REFRESH_TOKEN: 'refresh_token',
TOKEN_TYPE: 'token_type'
}

accessToken: string
refreshToken: string
tokenType: string

static load () {
const accessTokenLocalStorage = peertubeLocalStorage.getItem(this.KEYS.ACCESS_TOKEN)
const refreshTokenLocalStorage = peertubeLocalStorage.getItem(this.KEYS.REFRESH_TOKEN)
const tokenTypeLocalStorage = peertubeLocalStorage.getItem(this.KEYS.TOKEN_TYPE)

if (accessTokenLocalStorage && refreshTokenLocalStorage && tokenTypeLocalStorage) {
return new Tokens({
accessToken: accessTokenLocalStorage,
refreshToken: refreshTokenLocalStorage,
tokenType: tokenTypeLocalStorage
})
}

return null
}

static flush () {
peertubeLocalStorage.removeItem(this.KEYS.ACCESS_TOKEN)
peertubeLocalStorage.removeItem(this.KEYS.REFRESH_TOKEN)
peertubeLocalStorage.removeItem(this.KEYS.TOKEN_TYPE)
}

constructor (hash?: TokenOptions) {
if (hash) {
this.accessToken = hash.accessToken
this.refreshToken = hash.refreshToken

if (hash.tokenType === 'bearer') {
this.tokenType = 'Bearer'
} else {
this.tokenType = hash.tokenType
}
}
}

save () {
peertubeLocalStorage.setItem(Tokens.KEYS.ACCESS_TOKEN, this.accessToken)
peertubeLocalStorage.setItem(Tokens.KEYS.REFRESH_TOKEN, this.refreshToken)
peertubeLocalStorage.setItem(Tokens.KEYS.TOKEN_TYPE, this.tokenType)
}
}
import { TokenOptions, Tokens } from '../../../root-helpers/pure-auth-user.model'

export class AuthUser extends User implements ServerMyUserModel {
tokens: Tokens
Expand Down
2 changes: 1 addition & 1 deletion client/src/app/core/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'
import { Injectable } from '@angular/core'
import { Router } from '@angular/router'
import { Notifier } from '@app/core/notification/notifier.service'
import { objectToUrlEncoded, peertubeLocalStorage } from '@app/helpers'
import { objectToUrlEncoded, peertubeLocalStorage } from '@root-helpers/index'
import { I18n } from '@ngx-translate/i18n-polyfill'
import { MyUser as UserServerModel, OAuthClientLocal, User, UserLogin, UserRefreshToken } from '@shared/models'
import { environment } from '../../../environments/environment'
Expand Down
2 changes: 1 addition & 1 deletion client/src/app/core/rest/rest-table.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { peertubeLocalStorage } from '@app/helpers/peertube-web-storage'
import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage'
import { LazyLoadEvent, SortMeta } from 'primeng/api'
import { RestPagination } from './rest-pagination'
import { Subject } from 'rxjs'
Expand Down
3 changes: 2 additions & 1 deletion client/src/app/core/server/server.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { Observable, of, Subject } from 'rxjs'
import { first, map, share, shareReplay, switchMap, tap } from 'rxjs/operators'
import { HttpClient } from '@angular/common/http'
import { Inject, Injectable, LOCALE_ID } from '@angular/core'
import { getDevLocale, isOnDevLocale, peertubeLocalStorage, sortBy } from '@app/helpers'
import { getDevLocale, isOnDevLocale, sortBy } from '@app/helpers'
import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage'
import {
getCompleteLocale,
isDefaultLocale,
Expand Down
17 changes: 2 additions & 15 deletions client/src/app/core/users/user.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,10 @@ import {
UserRole,
VideoChannel
} from '@shared/models'
import { UserKeys } from '@root-helpers/user-keys'

export class User implements UserServerModel {
static KEYS = {
ID: 'id',
ROLE: 'role',
EMAIL: 'email',
VIDEOS_HISTORY_ENABLED: 'videos-history-enabled',
USERNAME: 'username',
NSFW_POLICY: 'nsfw_policy',
WEBTORRENT_ENABLED: 'peertube-videojs-' + 'webtorrent_enabled',
AUTO_PLAY_VIDEO: 'auto_play_video',
SESSION_STORAGE_AUTO_PLAY_NEXT_VIDEO: 'auto_play_next_video',
AUTO_PLAY_VIDEO_PLAYLIST: 'auto_play_video_playlist',
THEME: 'theme',
LAST_ACTIVE_THEME: 'last_active_theme',
VIDEO_LANGUAGES: 'video_languages'
}
static KEYS = UserKeys

id: number
username: string
Expand Down
2 changes: 1 addition & 1 deletion client/src/app/core/wrappers/storage.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Observable, Subject } from 'rxjs'
import { filter } from 'rxjs/operators'
import { Injectable } from '@angular/core'
import { peertubeLocalStorage, peertubeSessionStorage } from '@app/helpers'
import { peertubeLocalStorage, peertubeSessionStorage } from '@root-helpers/peertube-web-storage'

abstract class StorageService {
protected instance: Storage
Expand Down
1 change: 0 additions & 1 deletion client/src/app/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export * from './locales'
export * from './constants'
export * from './i18n-utils'
export * from './peertube-web-storage'
export * from './utils'
export * from './zone'
10 changes: 0 additions & 10 deletions client/src/app/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,6 @@ function immutableAssign <A, B> (target: A, source: B) {
return Object.assign({}, target, source)
}

function objectToUrlEncoded (obj: any) {
const str: string[] = []
for (const key of Object.keys(obj)) {
str.push(encodeURIComponent(key) + '=' + encodeURIComponent(obj[key]))
}

return str.join('&')
}

// Thanks: https://gist.github.com/ghinda/8442a57f22099bdb2e34
function objectToFormData (obj: any, form?: FormData, namespace?: string) {
const fd = form || new FormData()
Expand Down Expand Up @@ -207,7 +198,6 @@ export {
sortBy,
durationToString,
lineFeedToHtml,
objectToUrlEncoded,
getParameterByName,
populateAsyncUserVideoChannels,
getAbsoluteAPIUrl,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,98 +1,9 @@
@import 'variables';
@import 'mixins';
@import 'miniature';

.table-video-link {
@include disable-outline;

position: relative;
top: 3px;
}

.table-comment-link,
.table-account-link {
@include disable-outline;

color: var(--mainForegroundColor);

::ng-deep p:last-child {
margin: 0;
}
}

.table-account-link {
display: flex;
flex-direction: column;
}

.comment-flagged-account,
.account-flagged-handle {
font-size: 11px;
color: var(--greyForegroundColor);
}

.table-video {
display: inline-flex;

.table-video-image {
@include miniature-thumbnail;

$image-height: 45px;

height: $image-height;
width: #{(16/9) * $image-height};
margin-right: 0.5rem;
border-radius: 2px;
border: none;
background: transparent;
display: inline-flex;
justify-content: center;
align-items: center;
position: relative;

img {
height: 100%;
width: 100%;
border-radius: 2px;
}

span {
color: pvar(--inputPlaceholderColor);
}

.table-video-image-label {
@include static-thumbnail-overlay;
position: absolute;
border-radius: 3px;
font-size: 10px;
padding: 0 3px;
line-height: 1.3;
bottom: 2px;
right: 2px;
}
}

.table-video-text {
display: inline-flex;
flex-direction: column;
justify-content: center;
font-size: 90%;
color: pvar(--mainForegroundColor);
line-height: 1rem;

div .glyphicon {
font-size: 80%;
color: gray;
margin-left: 0.1rem;
}

div + div {
color: var(--greyForegroundColor);
font-size: 11px;
}
}
}

.abuse-states .glyphicon-comment {
margin-left: 0.5rem;
}
Expand Down
Loading

0 comments on commit ede0baf

Please sign in to comment.