+import { environment } from 'src/environments/environment'
import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core'
import { ActivatedRoute, Router } from '@angular/router'
import { AuthService, Notifier, RedirectService, SessionStorageService, UserService } from '@app/core'
import { FormReactive, FormReactiveService, InputTextComponent } from '@app/shared/shared-forms'
import { InstanceAboutAccordionComponent } from '@app/shared/shared-instance'
import { NgbAccordion, NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'
-import { PluginsManager } from '@root-helpers/plugins-manager'
+import { getExternalAuthHref } from '@shared/core-utils'
import { RegisteredExternalAuthConfig, ServerConfig } from '@shared/models'
@Component({
}
getAuthHref (auth: RegisteredExternalAuthConfig) {
- return PluginsManager.getExternalAuthHref(auth)
+ return getExternalAuthHref(environment.apiUrl, auth)
}
login () {
import { Injectable } from '@angular/core'
import { Router } from '@angular/router'
import { Notifier } from '@app/core/notification/notifier.service'
-import { logger, OAuthUserTokens, objectToUrlEncoded, peertubeLocalStorage } from '@root-helpers/index'
+import { logger, OAuthUserTokens, objectToUrlEncoded, peertubeLocalStorage, PluginsManager } from '@root-helpers/index'
import { HttpStatusCode, MyUser as UserServerModel, OAuthClientLocal, User, UserLogin, UserRefreshToken } from '@shared/models'
import { environment } from '../../../environments/environment'
import { RestExtractor } from '../rest/rest-extractor.service'
+import { ServerService } from '../server'
import { AuthStatus } from './auth-status.model'
import { AuthUser } from './auth-user.model'
private refreshingTokenObservable: Observable<any>
constructor (
+ private serverService: ServerService,
private http: HttpClient,
private notifier: Notifier,
private hotkeysService: HotkeysService,
const headers = new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded')
this.refreshingTokenObservable = this.http.post<UserRefreshToken>(AuthService.BASE_TOKEN_URL, body, { headers })
- .pipe(
- map(res => this.handleRefreshToken(res)),
- tap(() => {
- this.refreshingTokenObservable = null
- }),
- catchError(err => {
- this.refreshingTokenObservable = null
-
- logger.error(err)
- logger.info('Cannot refresh token -> logout...')
- this.logout()
- this.router.navigate([ '/login' ])
-
- return observableThrowError(() => ({
- error: $localize`You need to reconnect.`
- }))
- }),
- share()
- )
+ .pipe(
+ map(res => this.handleRefreshToken(res)),
+ tap(() => {
+ this.refreshingTokenObservable = null
+ }),
+ catchError(err => {
+ this.refreshingTokenObservable = null
+
+ logger.error(err)
+ logger.info('Cannot refresh token -> logout...')
+ this.logout()
+
+ const externalLoginUrl = PluginsManager.getDefaultLoginHref(environment.apiUrl, this.serverService.getHTMLConfig())
+ if (externalLoginUrl) window.location.href = externalLoginUrl
+ else this.router.navigate([ '/login' ])
+
+ return observableThrowError(() => ({
+ error: $localize`You need to reconnect.`
+ }))
+ }),
+ share()
+ )
return this.refreshingTokenObservable
}
import { HotkeysService } from 'angular2-hotkeys'
import * as debug from 'debug'
import { switchMap } from 'rxjs/operators'
+import { environment } from 'src/environments/environment'
import { ViewportScroller } from '@angular/common'
import { Component, OnInit, ViewChild } from '@angular/core'
import { Router } from '@angular/router'
}
getExternalLoginHref () {
- if (!this.serverConfig || this.serverConfig.client.menu.login.redirectOnSingleExternalAuth !== true) return undefined
-
- const externalAuths = this.serverConfig.plugin.registeredExternalAuths
- if (externalAuths.length !== 1) return undefined
-
- return PluginsManager.getExternalAuthHref(externalAuths[0])
+ return PluginsManager.getDefaultLoginHref(environment.apiUrl, this.serverConfig)
}
isRegistrationAllowed () {
import { firstValueFrom, ReplaySubject } from 'rxjs'
import { first, shareReplay } from 'rxjs/operators'
import { RegisterClientHelpers } from 'src/types/register-client-option.model'
-import { getHookType, internalRunHook } from '@shared/core-utils/plugins/hooks'
+import { getExternalAuthHref, getHookType, internalRunHook } from '@shared/core-utils/plugins/hooks'
import {
ClientHookName,
clientHookObject,
RegisterClientRouteOptions,
RegisterClientSettingsScriptOptions,
RegisterClientVideoFieldOptions,
- RegisteredExternalAuthConfig,
ServerConfigPlugin
} from '@shared/models'
import { environment } from '../environments/environment'
return isTheme ? '/themes' : '/plugins'
}
- static getExternalAuthHref (auth: RegisteredExternalAuthConfig) {
- return environment.apiUrl + `/plugins/${auth.name}/${auth.version}/auth/${auth.authName}`
+ static getDefaultLoginHref (apiUrl: string, serverConfig: HTMLServerConfig) {
+ if (!serverConfig || serverConfig.client.menu.login.redirectOnSingleExternalAuth !== true) return undefined
+ const externalAuths = serverConfig.plugin.registeredExternalAuths
+ if (externalAuths.length !== 1) return undefined
+
+ return getExternalAuthHref(apiUrl, externalAuths[0])
}
loadPluginsList (config: HTMLServerConfig) {
+import { RegisteredExternalAuthConfig } from '@shared/models'
import { HookType } from '../../models/plugins/hook-type.enum'
import { isCatchable, isPromise } from '../common/promises'
return result
}
+function getExternalAuthHref (apiUrl: string, auth: RegisteredExternalAuthConfig) {
+ return apiUrl + `/plugins/${auth.name}/${auth.version}/auth/${auth.authName}`
+}
+
export {
getHookType,
- internalRunHook
+ internalRunHook,
+ getExternalAuthHref
}