Code Monkey home page Code Monkey logo

go-plexauth's Introduction

Plex Authentication (in Go!)

GoDoc GitHub release (latest by date) License GitHub go.mod Go version

This tool is based on the instructions available in this Plex forum post, which you should look over to understand the authentication flow. To reiterate the high level steps, a PIN must be generated and formed into a URL that the user can visit which allows them to claim the PIN. After the PIN has been claimed, the Plex API will return an authentication token which can be used to access the Plex API on the user's behalf.

Go PlexAuth automates this process making it easy to obtain a permanent auth token for API calls.

Installation

As a Go library: go get github.com/BrenekH/go-plexauth

As a CLI: go install github.com/BrenekH/go-plexauth/cli@latest

Usage

CLI

Run the executable and enter a device name. You will then need to visit the URL it prints out to the console to complete the authentication. Once authentication is complete, your authentication token will be printed to the console.

Go Library

Basic example:

package main

import (
    "fmt"

    "github.com/BrenekH/go-plexauth"
)

func main() {
    clientID := "my-random-client-id"

    // Request that Plex generate a new PIN for a user to claim.
    pinID, pinCode, err := plexauth.GetPlexPIN(appName, clientID)
    if err != nil {
        panic(err)
    }

    // Create the URL that the user needs to visit to claim the PIN.
    authUrl, err := plexauth.GenerateAuthURL(appName, clientID, pinCode, plexauth.ExtraAuthURLOptions{})
    if err != nil {
        panic(err)
    }

    // Inform the user of the URL they need to visit. Typically this would
    // automatically open the browser, but here it is printed to the console for simplicity's sake.
    fmt.Printf("Please visit %s to authenticate.\n", authUrl)

    // Repeatedly ask Plex if the PIN has been claimed yet. Times out after 30 minutes.
    authToken, err := plexauth.PollForAuthToken(context.Background(), pinID, pinCode, clientID)
    if err != nil {
        panic(err)
    }

    fmt.Printf("Your authentication token is \"%s\"\n", authToken)
}

For the full documentation, visit pkg.go.dev/github.com/BrenekH/go-plexauth.

License

This project is licensed under the Apache 2.0 License, a copy of which can be found in LICENSE.

go-plexauth's People

Contributors

brenekh avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.