Documentation ¶
Index ¶
Examples ¶
Constants ¶
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 ¶
NewAuth returns a 3-legged authenticator with default host and authPath if scope is 0, then ScopeDataRead is set.
func (Auth) Authorize ¶
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.
type AuthRefresher ¶
type AuthToken ¶
type AuthToken struct { Auth Token *RefreshableToken }
func (AuthToken) GetTokenWithScope ¶
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 ¶
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 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