threelegged

package
v0.0.0-...-4946764 Latest Latest
Warning

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

Go to latest
Published: May 19, 2020 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	DefaultInformationalAPIPath = "userprofile/v1"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Auth

type Auth struct {
	oauth.AuthData
	RedirectURI string `json:"redirect_uri,omitempty"`
	Scope       scopes.Scope

	// Implicate will do an implicate token retrieval.
	// Do not use this unless you know what you are doing.
	Implicate bool
	// contains filtered or unexported fields
}

Auth struct holds data necessary for making requests in 3-legged context

func NewAuth

func NewAuth(clientID, clientSecret, redirectURI string, scope scopes.Scope) Auth

NewAuth returns a 3-legged authenticator with default host and authPath if scope is 0, then ScopeDataRead is set.

func (Auth) AuthToken

func (a Auth) AuthToken(code string) (AuthToken, error)

AuthToken will return an ForgeAuthenticator for the provided code

func (Auth) Authorize

func (a Auth) Authorize(state string) (string, error)

Authorize method returns an URL to redirect an end user, where it will be asked to give his consent for app to access the specified resources.

State can be used to specify, as URL-encoded payload, some arbitrary data that the authentication flow will pass back verbatim in a state query parameter to the callback URL.

Note: You do not call this URL directly in your server code.
See the Get a 3-Legged Token tutorial for more information on how to use this endpoint.

func (Auth) GetToken

func (a Auth) GetToken(code string) (bearer oauth.Bearer, err error)

GetToken is used to exchange the authorization code for a token and an exchange token

func (Auth) RefreshToken

func (a Auth) RefreshToken(refreshToken string) (bearer *oauth.Bearer, err error)

RefreshToken is used to get a new access token by using the refresh token provided by GetToken

type AuthRefresher

type AuthRefresher interface {
	RefreshToken(refresh_token string) (*oauth.Bearer, error)
}

type AuthToken

type AuthToken struct {
	Auth
	Token *RefreshableToken
}

func (AuthToken) GetTokenWithScope

func (a AuthToken) GetTokenWithScope(scope scopes.Scope) (*oauth.Bearer, error)

func (AuthToken) SetAuthHeader

func (a AuthToken) SetAuthHeader(scope scopes.Scope, header http.Header) error

type Authenticator

type Authenticator interface {
	Authorize(state string) (string, error)
	GetToken(code string) (oauth.Bearer, error)
	RefreshToken(refreshToken string) (*oauth.Bearer, error)
}

Authenticator interface defines the method necessary to qualify as 3-legged authenticator

type Information

type Information struct {
	APIPath string
	AuthToken
}

Information struct is holding the host and path used when making queries for profile of an authorizing end user in a 3-legged context

func (Information) AboutMe

func (info Information) AboutMe() (profile UserProfile, err error)

AboutMe is used to get the profile of an authorizing end user, given the token obtained via 3-legged OAuth flow

Example
package main

import (
	"fmt"

	"github.com/gdey/forge-api-go-client/oauth"

	"github.com/gdey/forge-api-go-client/oauth/threelegged"
)

func main() {

	aThreeLeggedToken := "put a valid 3-legged token here"
	Auth := threelegged.AuthToken{
		Token: threelegged.NewRefreshableToken(&oauth.Bearer{
			TokenType:   "Bearer",
			ExpiresIn:   60,
			AccessToken: aThreeLeggedToken,
		}),
	}

	info := threelegged.Information{
		AuthToken: Auth,
	}

	profile, err := info.AboutMe()

	if err != nil {
		fmt.Printf("[ERROR] Could not retrieve profile, got %s\n", err.Error())
		return
	}

	fmt.Printf("Received profile:\n"+
		"UserId: %s\n"+
		"UserName: %s\n"+
		"EmailId: %s\n"+
		"FirstName: %s\n"+
		"LastName: %s\n"+
		"EmailVerified: %t\n"+
		"Var2FaEnabled: %t\n"+
		"ProfileImages: %v",
		profile.UserID,
		profile.UserName,
		profile.EmailID,
		profile.FirstName,
		profile.LastName,
		profile.EmailVerified,
		profile.Var2FaEnabled,
		profile.ProfileImages,
	)
}
Output:

func (Information) Path

func (info Information) Path(paths ...string) []string

type RefreshableToken

type RefreshableToken struct {
	TokenExpireTime time.Time
	// contains filtered or unexported fields
}

func NewRefreshableToken

func NewRefreshableToken(bearer *oauth.Bearer) *RefreshableToken

func (*RefreshableToken) Bearer

func (t *RefreshableToken) Bearer() *oauth.Bearer

func (*RefreshableToken) RefreshTokenIfRequired

func (t *RefreshableToken) RefreshTokenIfRequired(auth AuthRefresher) error

type TokenRefresher

type TokenRefresher interface {
	Bearer() *oauth.Bearer
	RefreshTokenIfRequired(auth Auth) error
}

type UserProfile

type UserProfile struct {
	UserID    string `json:"userId"`    // The backend user ID of the profile
	UserName  string `json:"userName"`  // The username chosen by the user
	EmailID   string `json:"emailId"`   // The user’s email address
	FirstName string `json:"firstName"` // The user’s first name
	LastName  string `json:"lastName"`  // The user’s last name
	// true if the user’s email address has been verified false if the user’s email address has not been verified
	EmailVerified bool `json:"emailVerified"`
	// true if the user has enabled two-factor authentication false if the user has not enabled two-factor authentication
	Var2FaEnabled bool `json:"2FaEnabled"`
	// A flat JSON object of attribute-value pairs in which the attributes specify available profile image sizes in the
	// format sizeX<pixels> (where <pixels> is an integer that represents both height and width in pixels of square
	// profile images) and the values are URLs for downloading the images via HTTP
	ProfileImages interface{} `json:"profileImages"`
}

UserProfile reflects the response received when query the profile of an authorizing end user in a 3-legged context

Jump to

Keyboard shortcuts

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