authclient

package module
v0.0.0-...-bb72a66 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2020 License: GPL-3.0 Imports: 2 Imported by: 0

README

Authentication Client Library

For Floor Gang bot. Every command should interface with this library to authorize each user that uses an admin-related command. It does this by communicating to a process over RPC+HTTP. You should use this library to verify each guild member trying to execute a command. This is easy to do.

Make sure an instance of authserver is running on your local machine where the authclient can reach it.

Example Usage

package main

import auth "github.com/Floor-Gang/authclient"

func main() {
    client := auth.GetClient("http://localhost:6969")
    
    memberID := "1234"
    
    // result will be an AuthResponse which includes two properties:
    // IsAdmin (boolean): Whether or not they're allowed to us the command
    // Role (string): The ID of the role that's enabling them.
    result := client.Auth("member ID 1234")
   
    if result.IsAdmin {
    	// do stuff...
    } else {
        // tell them they're not allowed to use the command
    }
}

Notes

What if the auth server is down?

Don't allow execution of a given command, and certainly don't setup your own authentication process unless it's specialized to particular roles rather than the shared ones stored in the authserver

What if the auth server has an issue?

Report it here

Getting

Since this library is under a private repository knowledge yourself about getting packages in Go from private repositories.

Make sure your enviroment variable "GOPRIVATE" includes the following

export GOPRIVATE='github.com/floor-gang'

Finally run this to get the library

$ go get github.com/Floor-Gang/authclient@latest

Versioning

X.Y

  • X: A major change has happened, please update your code.
  • Y: A patch was implemented.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthClient

type AuthClient struct {
	// contains filtered or unexported fields
}

func GetClient

func GetClient(address string) (AuthClient, error)

func (AuthClient) Auth

func (ac AuthClient) Auth(memberID string) (pkg.AuthResponse, error)

func (AuthClient) Register

func (ac AuthClient) Register(feature Feature) (RegisterResponse, error)

func (AuthClient) Verify

func (ac AuthClient) Verify(memberID string) (bool, error)

type Feature

type Feature struct {
	Name          string       // ie. ".admin"
	Description   string       // "For managing administrator"
	Commands      []SubCommand // Optionally empty
	CommandPrefix string       // Optionally empty
}

Feature to register.

type RegisterResponse

type RegisterResponse struct {
	Token   string // A Discord bot access token
	Serving string // The ID of the Guild being served
}

Response from the server while registering.

type SubCommand

type SubCommand struct {
	Name        string   // ie. "add"
	Description string   // ie. "This is for adding administrator roles"
	Example     []string // ie. [".admin", "add", "...role ID's"]
}

Commands that come with this feature.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL