auth

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const AuthURL = "https://auth.worksmobile.com/oauth2/v2.0/authorize"
View Source
const CONFIG_DIR_NAME = ".config"
View Source
const CONFIG_OAUTH_FILE_NAME = "oauth.toml"
View Source
const CONFIG_PATH_ENV_NAME = "LINEWORKS_CONFIG_DIR"
View Source
const CONFIG_SERVICE_ACCOUNT_FILE_NAME = "service_account.toml"
View Source
const CONFIG_SERVICE_DIR_NAME = "lineworks"
View Source
const CONFIG_TOKEN_FILE_NAME = "token.toml"
View Source
const TokenURL = "https://auth.worksmobile.com/oauth2/v2.0/token"

Variables

This section is empty.

Functions

func GenerateJWT

func GenerateJWT(clientId string, serviceAccountId string, privateKey string) string

Generate JWT

func ListConfigProfiles

func ListConfigProfiles() []string

func StartCallbackServer

func StartCallbackServer(ctx context.Context, addr string, port string, path string, timeoutSec int16, callback func(code string, state string) error)

Start callback local server

Types

type AccessTokenJWTRequestBody

type AccessTokenJWTRequestBody struct {
	Assertion    string `json:"assertion"`
	GrantType    string `json:"grant_type"`
	ClientID     string `json:"client_id"`
	ClientSecret string `json:"client_secret"`
	Scopes       string `json:"scope"`
}

type AccessTokenRequestBody

type AccessTokenRequestBody struct {
	Code         string `json:"code"`
	GrantType    string `json:"grant_type"`
	ClientID     string `json:"client_id"`
	ClientSecret string `json:"client_secret"`
	Domain       string `json:"domain,omitempty"`
}

type AccessTokenResponseBody

type AccessTokenResponseBody struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	Scopes       string `json:"scope"`
	ExpiredIn    string `json:"expires_in"`
	TokenType    string `json:"token_type"`
}

func RequestAccessToken

func RequestAccessToken(req_body AccessTokenRequestBody) (AccessTokenResponseBody, error)

Get AccessToken

func RequestAccessTokenJWT

func RequestAccessTokenJWT(req_body AccessTokenJWTRequestBody) (AccessTokenResponseBody, error)

Get AccessToken (JWT)

type CallbackHandler

type CallbackHandler struct {
	Context       context.Context
	ContextCancel context.CancelFunc
	CallbackFunc  func(code string, state string) error
}

func (*CallbackHandler) ServeHTTP

func (handler *CallbackHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ClientCredential

type ClientCredential struct {
	ClientID     string `toml:"client_id" json:"client_id"`
	ClientSecret string `toml:"client_secret" json:"client_secret"`
	Scopes       string `toml:"scopes" json:"scopes"`
	ListenAddr   string `toml:"addr" json:"addr"`
	ListenPort   string `toml:"port" json:"port"`
	RedirectPath string `toml:"path" json:"path"`
	DomainID     string `toml:"domain_id,omitempty" json:"domain_id,omitempty"`
}

func (*ClientCredential) AuthCodeURL

func (cred *ClientCredential) AuthCodeURL(state string) string

Generate Authorization Code URL

func (*ClientCredential) GetAccessToken

func (cred *ClientCredential) GetAccessToken(code string) Token

Get access token

func (*ClientCredential) GetAccessTokenJWT

func (cred *ClientCredential) GetAccessTokenJWT(sva ServiceAccount) Token

Get access token (JWT)

func (*ClientCredential) GetRedirectUrl

func (cred *ClientCredential) GetRedirectUrl() string

Get Redirect URL

func (ClientCredential) ReadConfig

func (cred ClientCredential) ReadConfig(profile string) (*ClientCredential, error)

func (*ClientCredential) WriteConfig

func (cred *ClientCredential) WriteConfig(profile string) error

type RefreshTokenRequestBody

type RefreshTokenRequestBody struct {
	RefreshToken string `json:"refresh_token"`
	GrantType    string `json:"grant_type"`
	ClientID     string `json:"client_id"`
	ClientSecret string `json:"client_secret"`
}

type RefreshTokenResponseBody

type RefreshTokenResponseBody struct {
	AccessToken string `json:"access_token"`
	Scopes      string `json:"scope"`
	ExpiredIn   string `json:"expires_in"`
	TokenType   string `json:"token_type"`
}

type ServiceAccount

type ServiceAccount struct {
	ServiceAccountID string `toml:"service_account_id" json:"service_account_id"`
	PrivateKey       string `toml:"private_key" json:"private_key"`
}

func (ServiceAccount) ReadConfig

func (sa ServiceAccount) ReadConfig(profile string) (*ServiceAccount, error)

func (*ServiceAccount) WriteConfig

func (sa *ServiceAccount) WriteConfig(profile string) error

type Token

type Token struct {
	AccessToken  string `toml:"access_token" json:"access_token"`
	RefreshToken string `toml:"refresh_token" json:"refresh_token"`
	Scopes       string `toml:"scopes" json:"scopes"`
	ExpiredIn    string `toml:"expired_in" json:"expired_in"`
}

func (Token) ReadConfig

func (token Token) ReadConfig(profile string) (*Token, error)

func (*Token) WriteConfig

func (token *Token) WriteConfig(profile string) error

Jump to

Keyboard shortcuts

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