go_mojoauth

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2022 License: MIT Imports: 3 Imported by: 0

README

MojoAuth

MojoAuth Go SDK

Documentation

  • Configuration - Everything you need to begin using the MojoAuth SDK.

Installation

To install, run: go get github.com/mojoauth/go-sdk

Import the package:

import "github.com/mojoauth/go-sdk"

Install all package dependencies by running go get ./... in the root folder of this SDK.

Usage

Take a peek:

Before making any API calls, the MojoAuth API client must be initialized with your MojoAuth API key.

Sample code:

cfg := go-sdk.Config{
  ApiKey: "<Enter ApiKey>",
}

mojoclient, err := go_mojoauth.NewMojoAuth(&cfg)

if err != nil {
  errors = errors + err.(mojoerror.Error).OrigErr().Error()
  //		respCode = 500
}

How to contribute

We appreciate all kinds of contributions from anyone, be it finding an issue or writing a blog.

Please check the contributing guide to become a contributor.

License

For more information on licensing, please refer to License

Documentation

Index

Constants

This section is empty.

Variables

View Source
var JSONHeader = map[string]string{"content-Type": "application/json"}
View Source
var URLEncodedHeader = map[string]string{"content-Type": "application/x-www-form-urlencoded"}

Functions

This section is empty.

Types

type Config

type Config struct {
	ApiKey string
}

Config struct contains MojoAuth credentials and is used when initalizing the MojoAuth API client struct

type Context

type Context struct {
	ApiKey string
	Jwks   string
	Token  string
}

Context struct is a field in the MojoAuth struct

type Mojoauth

type Mojoauth struct {
	Context *Context
	Domain  string
}

MojoAuth struct holds context for intializing the MojoAuth client and the domain for API calls Domain can be changed after intialization

func NewMojoAuth

func NewMojoAuth(cfg *Config, optionalArgs ...map[string]string) (*Mojoauth, error)

NewMojoAuth initializes a new MojoAuth struct with a Config struct Config struct must contain the ApiKey and ApiSecret of your MojoAuth site Example:

cfg := lr.Config{
	ApiKey:    os.Getenv("APIKEY"),
	ApiSecret: os.Getenv("APISECRET"),
}
lrclient, _ := lr.NewMojoAuth(&cfg)

It also takes optional variadic arguments Some APIs require for an access token to be passed with Authorization Bearer header Initialize MojoAuth struct with a token passed in the variadic argument like so:

lrclient, _ := lr.NewMojoAuth(&cfg, map[string]string{"token": "9c3208ae-2848-4ac5-baef-41dd4103e263"})

func (Mojoauth) AddApiCredentialsToReqHeader

func (mojo Mojoauth) AddApiCredentialsToReqHeader(req *httprutils.Request)

AddApiCredentialsToReqHeader removes the X-API-Key query parameter from a constructed request and add MojoAuth app credentials in the request headers

func (Mojoauth) NewDeleteReq

func (mojo Mojoauth) NewDeleteReq(path string, body ...interface{}) *httprutils.Request

NewDeleteReq takes a uri, body, and optional queries to construct a DELETE request for a MojoAuth POST API endpoint

func (Mojoauth) NewDeleteReqWithToken

func (mojo Mojoauth) NewDeleteReqWithToken(path string, body interface{}, queries ...map[string]string) (*httprutils.Request, error)

NewDeleteReqWithToken takes a uri and query parameters, then constructs a PUT request for MojoAuth API endpoints requiring access tokens being passed in Authorization Bearer header

func (Mojoauth) NewGetReq

func (mojo Mojoauth) NewGetReq(path string, queries ...map[string]string) *httprutils.Request

NewGetRequest takes a uri and query parameters, then constructs a GET request for a MojoAuth API endpoint

func (Mojoauth) NewGetReqWithToken

func (mojo Mojoauth) NewGetReqWithToken(path string, queries ...map[string]string) (*httprutils.Request, error)

NewGetRequest takes a uri and query parameters, then constructs a GET request for MojoAuth API endpoints requiring access tokens being passed in Authorization Bearer header

func (Mojoauth) NewPostReq

func (mojo Mojoauth) NewPostReq(path string, body interface{}, queries ...map[string]string) (*httprutils.Request, error)

NewPostReq takes a uri, body, and optional queries to construct a POST request for a MojoAuth POST API endpoint

func (Mojoauth) NewPostReqWithToken

func (mojo Mojoauth) NewPostReqWithToken(path string, body interface{}, queries ...map[string]string) (*httprutils.Request, error)

NewPostReqWithToken takes a uri, body, and query parameters, then constructs the request for MojoAuth PUT API end points requiring access tokens being passed in Authorization Bearer header

func (Mojoauth) NewPutReq

func (mojo Mojoauth) NewPutReq(path string, body interface{}, queries ...map[string]string) (*httprutils.Request, error)

NewPutReq takes a uri, body, and optional queries to construct a PUT request for a MojoAuth API endpoint

func (Mojoauth) NewPutReqWithToken

func (mojo Mojoauth) NewPutReqWithToken(path string, body interface{}, queries ...map[string]string) (*httprutils.Request, error)

NewPutReqWithToken takes a uri and query parameters, then constructs a PUT request for MojoAuth API endpoints requiring access tokens being passed in Authorization Bearer header

func (Mojoauth) NormalizeApiKey

func (mojo Mojoauth) NormalizeApiKey(req *httprutils.Request)

NormalizeApiKey normalizes the apikey parameter in queries for requests to be sent to MojoAuth endpoints that only accept "apikey"

Directories

Path Synopsis
The mojobody package holds the structs to be encoded as the body in POST and PUT calls These structs are meant to serve as convenient measures assisting API calls provided by the MojoAuth Go SDK All functions in this SDK takes interface{} as the body, but initiating your data in the appropriate struct and passing in place of the body when calling the SDK functions will ensure the parameters submitted are correctly formatted and named for the MojoAuth APIs The usage of the structs in this package is optional and provided for convenience only Majority of methods take map[string]string as body parameter as well.
The mojobody package holds the structs to be encoded as the body in POST and PUT calls These structs are meant to serve as convenient measures assisting API calls provided by the MojoAuth Go SDK All functions in this SDK takes interface{} as the body, but initiating your data in the appropriate struct and passing in place of the body when calling the SDK functions will ensure the parameters submitted are correctly formatted and named for the MojoAuth APIs The usage of the structs in this package is optional and provided for convenience only Majority of methods take map[string]string as body parameter as well.

Jump to

Keyboard shortcuts

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