mirror of
				https://github.com/owncast/owncast.git
				synced 2025-11-04 05:17:27 +08:00 
			
		
		
		
	* Able to authenticate user against IndieAuth. For #1273 * WIP server indieauth endpoint. For https://github.com/owncast/owncast/issues/1272 * Add migration to remove access tokens from user * Add authenticated bool to user for display purposes * Add indieauth modal and auth flair to display names. For #1273 * Validate URLs and display errors * Renames, cleanups * Handle relative auth endpoint paths. Add error handling for missing redirects. * Disallow using display names in use by registered users. Closes #1810 * Verify code verifier via code challenge on callback * Use relative path to authorization_endpoint * Post-rebase fixes * Use a timestamp instead of a bool for authenticated * Propertly handle and display error in modal * Use auth'ed timestamp to derive authenticated flag to display in chat * don't redirect unless a URL is present avoids redirecting to `undefined` if there was an error * improve error message if owncast server URL isn't set * fix IndieAuth PKCE implementation use SHA256 instead of SHA1, generates a longer code verifier (must be 43-128 chars long), fixes URL-safe SHA256 encoding * return real profile data for IndieAuth response * check the code verifier in the IndieAuth server * Linting * Add new chat settings modal anad split up indieauth ui * Remove logging error * Update the IndieAuth modal UI. For #1273 * Add IndieAuth repsonse error checking * Disable IndieAuth client if server URL is not set. * Add explicit error messages for specific error types * Fix bad logic * Return OAuth-keyed error responses for indieauth server * Display IndieAuth error in plain text with link to return to main page * Remove redundant check * Add additional detail to error * Hide IndieAuth details behind disclosure details * Break out migration into two steps because some people have been runing dev in production * Add auth option to user dropdown Co-authored-by: Aaron Parecki <aaron@parecki.com>
		
			
				
	
	
		
			138 lines
		
	
	
		
			3.4 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			138 lines
		
	
	
		
			3.4 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
package core
 | 
						|
 | 
						|
import (
 | 
						|
	"os"
 | 
						|
	"path"
 | 
						|
	"path/filepath"
 | 
						|
 | 
						|
	log "github.com/sirupsen/logrus"
 | 
						|
 | 
						|
	"github.com/owncast/owncast/auth"
 | 
						|
	"github.com/owncast/owncast/config"
 | 
						|
	"github.com/owncast/owncast/core/chat"
 | 
						|
	"github.com/owncast/owncast/core/data"
 | 
						|
	"github.com/owncast/owncast/core/rtmp"
 | 
						|
	"github.com/owncast/owncast/core/transcoder"
 | 
						|
	"github.com/owncast/owncast/core/user"
 | 
						|
	"github.com/owncast/owncast/core/webhooks"
 | 
						|
	"github.com/owncast/owncast/models"
 | 
						|
	"github.com/owncast/owncast/notifications"
 | 
						|
	"github.com/owncast/owncast/utils"
 | 
						|
	"github.com/owncast/owncast/yp"
 | 
						|
)
 | 
						|
 | 
						|
var (
 | 
						|
	_stats       *models.Stats
 | 
						|
	_storage     models.StorageProvider
 | 
						|
	_transcoder  *transcoder.Transcoder
 | 
						|
	_yp          *yp.YP
 | 
						|
	_broadcaster *models.Broadcaster
 | 
						|
	handler      transcoder.HLSHandler
 | 
						|
	fileWriter   = transcoder.FileWriterReceiverService{}
 | 
						|
)
 | 
						|
 | 
						|
// Start starts up the core processing.
 | 
						|
func Start() error {
 | 
						|
	resetDirectories()
 | 
						|
 | 
						|
	data.PopulateDefaults()
 | 
						|
 | 
						|
	if err := data.VerifySettings(); err != nil {
 | 
						|
		log.Error(err)
 | 
						|
		return err
 | 
						|
	}
 | 
						|
 | 
						|
	if err := setupStats(); err != nil {
 | 
						|
		log.Error("failed to setup the stats")
 | 
						|
		return err
 | 
						|
	}
 | 
						|
 | 
						|
	// The HLS handler takes the written HLS playlists and segments
 | 
						|
	// and makes storage decisions.  It's rather simple right now
 | 
						|
	// but will play more useful when recordings come into play.
 | 
						|
	handler = transcoder.HLSHandler{}
 | 
						|
 | 
						|
	if err := setupStorage(); err != nil {
 | 
						|
		log.Errorln("storage error", err)
 | 
						|
	}
 | 
						|
 | 
						|
	user.SetupUsers()
 | 
						|
	auth.Setup(data.GetDatastore())
 | 
						|
 | 
						|
	fileWriter.SetupFileWriterReceiverService(&handler)
 | 
						|
 | 
						|
	if err := createInitialOfflineState(); err != nil {
 | 
						|
		log.Error("failed to create the initial offline state")
 | 
						|
		return err
 | 
						|
	}
 | 
						|
 | 
						|
	_yp = yp.NewYP(GetStatus)
 | 
						|
 | 
						|
	if err := chat.Start(GetStatus); err != nil {
 | 
						|
		log.Errorln(err)
 | 
						|
	}
 | 
						|
 | 
						|
	// start the rtmp server
 | 
						|
	go rtmp.Start(setStreamAsConnected, setBroadcaster)
 | 
						|
 | 
						|
	rtmpPort := data.GetRTMPPortNumber()
 | 
						|
	log.Infof("RTMP is accepting inbound streams on port %d.", rtmpPort)
 | 
						|
 | 
						|
	webhooks.InitWorkerPool()
 | 
						|
 | 
						|
	notifications.Setup(data.GetStore())
 | 
						|
 | 
						|
	return nil
 | 
						|
}
 | 
						|
 | 
						|
func createInitialOfflineState() error {
 | 
						|
	transitionToOfflineVideoStreamContent()
 | 
						|
 | 
						|
	return nil
 | 
						|
}
 | 
						|
 | 
						|
// transitionToOfflineVideoStreamContent will overwrite the current stream with the
 | 
						|
// offline video stream state only.  No live stream HLS segments will continue to be
 | 
						|
// referenced.
 | 
						|
func transitionToOfflineVideoStreamContent() {
 | 
						|
	log.Traceln("Firing transcoder with offline stream state")
 | 
						|
 | 
						|
	_transcoder := transcoder.NewTranscoder()
 | 
						|
	_transcoder.SetIdentifier("offline")
 | 
						|
	_transcoder.SetLatencyLevel(models.GetLatencyLevel(4))
 | 
						|
	_transcoder.SetIsEvent(true)
 | 
						|
 | 
						|
	offlineFilePath, err := saveOfflineClipToDisk("offline.ts")
 | 
						|
	if err != nil {
 | 
						|
		log.Fatalln("unable to save offline clip:", err)
 | 
						|
	}
 | 
						|
 | 
						|
	_transcoder.SetInput(offlineFilePath)
 | 
						|
	go _transcoder.Start()
 | 
						|
 | 
						|
	// Copy the logo to be the thumbnail
 | 
						|
	logo := data.GetLogoPath()
 | 
						|
	if err = utils.Copy(filepath.Join("data", logo), "webroot/thumbnail.jpg"); err != nil {
 | 
						|
		log.Warnln(err)
 | 
						|
	}
 | 
						|
 | 
						|
	// Delete the preview Gif
 | 
						|
	_ = os.Remove(path.Join(config.WebRoot, "preview.gif"))
 | 
						|
}
 | 
						|
 | 
						|
func resetDirectories() {
 | 
						|
	log.Trace("Resetting file directories to a clean slate.")
 | 
						|
 | 
						|
	// Wipe hls data directory
 | 
						|
	utils.CleanupDirectory(config.HLSStoragePath)
 | 
						|
 | 
						|
	// Remove the previous thumbnail
 | 
						|
	logo := data.GetLogoPath()
 | 
						|
	if utils.DoesFileExists(logo) {
 | 
						|
		err := utils.Copy(path.Join("data", logo), filepath.Join(config.WebRoot, "thumbnail.jpg"))
 | 
						|
		if err != nil {
 | 
						|
			log.Warnln(err)
 | 
						|
		}
 | 
						|
	}
 | 
						|
}
 |