PTGUoauth

package
v1.0.17 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2024 License: MIT Imports: 7 Imported by: 1

README

PTGU OAuth Line

Import

import (
	PTGUoauth "github.com/parinyapt/golang_utils/oauth/line/v1"
)

Example

Config OAuth
lineOAuth := PTGUoauth.NewLineOAuth(&PTGUoauth.LineOAuthConfig{
  ClientID:     "xxxxxxxxxx",
  ClientSecret: "xxxxxxxxxx",
  RedirectURL:  "https://example.com/callback",
})
Generate Login URL
loginURL := lineOAuth.GenerateOAuthURL(PTGUoauth.OptionLineGenerateOAuthURL{
  Scopes: []string{
    "openid",
    "profile",
    "email",
  },
  State: "xxxxxxxxxx",
})
Get Access, Refresh, ID Token by Auth Code
tokenData, err := lineOAuth.GetToken("NVkNw1K197uvr0eLOYNc")
if err != nil {
  panic(err)
}
fmt.Println("AccessToken : " + tokenData.AccessToken)
fmt.Println(tokenData.ExpiresIn)
fmt.Println("IDToken : " + tokenData.IDToken)
fmt.Println("RefreshToken : " + tokenData.RefreshToken)
fmt.Println("Scope : " + tokenData.Scope)
fmt.Println("TokenType : " + tokenData.TokenType)
Get ID Token Info
idTokenInfo, err := lineOAuth.GetIDTokenInfo("eyJ0eXAi....")
if err != nil {
  panic(err)
}
fmt.Println("Nonce : " + PTGUdata.PointerToStringValue(idTokenInfo.Nonce))
fmt.Println("UserID : " + idTokenInfo.Sub)
fmt.Println("Name : " + PTGUdata.PointerToStringValue(idTokenInfo.Name))
fmt.Println("Picture : " + PTGUdata.PointerToStringValue(idTokenInfo.Picture))
fmt.Println("Email : " + PTGUdata.PointerToStringValue(idTokenInfo.Email))

Documentation

Index

Constants

View Source
const (
	LineOAuthURL       = "https://access.line.me/oauth2/v2.1/authorize"
	LineTokenURL       = "https://api.line.me/oauth2/v2.1/token"
	LineVerifyTokenURL = "https://api.line.me/oauth2/v2.1/verify"
)

Variables

This section is empty.

Functions

func NewLineOAuth

func NewLineOAuth(inputConfig *LineOAuthConfig) *lineOAuthReceiverArgument

Types

type LineIDTokenInfoResponse

type LineIDTokenInfoResponse struct {
	// Issuer should be https://access.line.me
	Iss string `json:"iss"`
	// User ID
	Sub string `json:"sub"`
	// Channel ID
	Aud string `json:"aud"`
	// The expiry date of the ID token in UNIX time.
	Exp int64 `json:"exp"`
	// The time the ID token was issued in UNIX time.
	Iat int64 `json:"iat"`
	// Time when the user was authenticated in UNIX time. Not included if the max_age parameter wasn't specified in the authorization request.
	AuthTime *int64 `json:"auth_time"`
	// The nonce value specified in the authorization request. This claim is returned only if a nonce value is specified in the authorization request.
	Nonce *string `json:"nonce"`
	// User authentication method. The following values are possible: pwd, lineautologin, lineqr, and linesso.
	Amr []string `json:"amr"`
	// User's display name (only returned if the `profile` scope is specified)
	Name *string `json:"name"`
	// User's profile image URL (only returned if the `profile` scope is specified)
	Picture *string `json:"picture"`
	// User's email address (only returned if the `email` scope is specified)
	Email *string `json:"email"`
}

type LineOAuthConfig

type LineOAuthConfig struct {
	// LINE Login Channel ID.
	ClientID string
	// Channel secret
	ClientSecret string
	// Callback URL
	RedirectURL string
}

type LineOAuthMethod

type LineOAuthMethod interface {
	// GenerateOAuthURL is a function to generate oauth url for user to login
	GenerateOAuthURL(option OptionLineGenerateOAuthURL) (oauthURL string)

	// GetAccessToken is a function to get user access token by code that response from google
	GetToken(code string) (tokenData LineTokenResponse, err error)

	// GetIDTokenInfo is a function to get id token info from line server
	GetIDTokenInfo(idToken string) (idTokenInfo LineIDTokenInfoResponse, err error)
}

type LineTokenInfoErrorResponse

type LineTokenInfoErrorResponse struct {
	Error            string `json:"error"`
	ErrorDescription string `json:"error_description"`
}

type LineTokenInfoRequest

type LineTokenInfoRequest struct {
	IDToken  string `form:"id_token"`
	ClientID string `form:"client_id"`
}

type LineTokenRequest

type LineTokenRequest struct {
	GrantType    string `form:"grant_type"`
	Code         string `form:"code"`
	RedirectURI  string `form:"redirect_uri"`
	ClientID     string `form:"client_id"`
	ClientSecret string `form:"client_secret"`
}

type LineTokenResponse

type LineTokenResponse struct {
	// Access token. Valid for 30 days.
	AccessToken string `json:"access_token"`
	// Expiration time of access token (in seconds).
	ExpiresIn    int64  `json:"expires_in"`
	IDToken      string `json:"id_token"`
	RefreshToken string `json:"refresh_token"`
	Scope        string `json:"scope"`
	TokenType    string `json:"token_type"`
}

type OptionLineGenerateOAuthURL

type OptionLineGenerateOAuthURL struct {
	// Valid values: `openid`, `profile`, `email`
	Scopes []string
	// A unique alphanumeric string used to prevent cross-site request forgery attacks. This value is returned in the ID token.
	State string
	// A string used to prevent replay attacks (opens new window). This value is returned in an ID token.
	Nonce string
	// Set to `consent` to force the consent screen to appear even if the user has already granted all requested permissions.
	Prompt string
	// The max_age request parameter prevents the user from being auto-logged in using cookies.
	MaxAge int64
	// Display language for LINE Login screens ex. en-US.
	UiLocales string
	// Displays an option to add a LINE Official Account as a friend during login. Set to either `normal` or `aggressive`
	BotPrompt string
	// Set to `lineqr` to display the QR code on the login screen by default.
	InitialAmrDisplay string
	// Set to `true` to hide the buttons for changing the login method, such as "Log in with email" or "QR code login".
	SwitchAmr bool
	// If set to `true`, Auto login will be disabled. The default value is false.
	DisableAutoLogin bool
	// If set to `true`, Auto login will be disabled in iOS. The default value is false.
	DisableIosAutoLogin bool

	CodeChallenge       string
	CodeChallengeMethod string
}

Jump to

Keyboard shortcuts

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