OpencastAuth
The OpencastAuth authentication system provides an interface for managing authentication and authorization with Opencast services.
OpencastAuth Interface
Section titled “OpencastAuth Interface”export interface OpencastAuth { getLoggedUserName: () => Promise<string | null> isAnonymous: () => Promise<boolean> canRead: () => Promise<boolean> canWrite: () => Promise<boolean> auth: (redirectUrl?: string) => Promise<void>}Methods
Section titled “Methods”getLoggedUserName
Section titled “getLoggedUserName”getLoggedUserName(): Promise<string | null>Gets the name of the authenticated user.
Returns: The user name or null if not authenticated.
isAnonymous
Section titled “isAnonymous”isAnonymous(): Promise<boolean>Checks if the current user is anonymous.
Returns: true if the user is anonymous, false otherwise.
canRead
Section titled “canRead”canRead(): Promise<boolean>Checks if the user has read permissions.
Returns: true if they have read permissions, false otherwise.
canWrite
Section titled “canWrite”canWrite(): Promise<boolean>Checks if the user has write permissions.
Returns: true if they have write permissions, false otherwise.
auth(redirectUrl?: string): Promise<void>Starts the authentication process.
Parameters:
redirectUrl: string (optional) - URL to redirect to after authentication
OpencastAuthDefaultImpl
Section titled “OpencastAuthDefaultImpl”Default implementation of the Opencast authentication system.
export class OpencastAuthDefaultImpl implements OpencastAuthConstructor
Section titled “Constructor”constructor(player?: OpencastPaellaPlayer)Parameters:
player: OpencastPaellaPlayer (optional) - Player instance
Properties
Section titled “Properties”player
Section titled “player”get player(): OpencastPaellaPlayer | nullset player(player: OpencastPaellaPlayer)Reference to the Paella Opencast player.
Functionalities
Section titled “Functionalities”The default implementation:
- Gets user information from the
/info/me.jsonOpencast endpoint - Caches user information to avoid multiple requests
- Handles authentication errors gracefully
- Integrates with player logging for debugging
User information endpoint
Section titled “User information endpoint”The implementation uses the standard Opencast endpoint:
GET /info/me.jsonThis endpoint returns information about the current authenticated user, including:
- Username
- Roles and permissions
- Authentication status
Configuration
Section titled “Configuration”Authentication can be configured in the initialization parameters:
const player = new OpencastPaellaPlayer('container', { opencast: { auth: new CustomAuthImpl(), // Custom implementation // or use default implementation (automatic) }});Usage example
Section titled “Usage example”import { OpencastPaellaPlayer, OpencastAuthDefaultImpl } from '@asicupv/paella-opencast-core';
const auth = new OpencastAuthDefaultImpl();const player = new OpencastPaellaPlayer('player-container', { opencast: { auth: auth, presentationUrl: 'https://opencast.example.com' }});