A Go SDK for LINE Login v2.1 API with 100% API coverage.
Note: This SDK was originally part of the Social API and has been migrated into LINE Login SDK since 2020/11/20. See official announcement.
go get github.com/kkdai/line-login-sdk-go| API | Method | Description |
|---|---|---|
| Issue access token | GetAccessToken() |
Issues access tokens |
| Issue access token (PKCE) | GetAccessTokenPKCE() |
Issues access tokens with PKCE |
| Verify access token | TokenVerify() |
Verifies access token validity |
| Refresh access token | RefreshToken() |
Refreshes access tokens |
| Revoke access token | RevokeToken() |
Revokes access tokens |
| Verify ID token | VerifyIDToken() |
Verifies ID token authenticity |
| API | Method | Description |
|---|---|---|
| Get user profile | GetUserProfile() |
Gets user's display name, profile image, and status message |
| Get user information | GetUserInfo() |
Gets user info via OIDC userinfo endpoint |
| Get friendship status | GetFriendshipStatus() |
Gets friendship status with LINE Official Account |
| API | Method | Description |
|---|---|---|
| Deauthorize | Deauthorize() |
Revokes user permissions (for GDPR compliance) |
| Function | Description |
|---|---|
GetWebLoinURL() |
Generates LINE Login authorization URL |
GetPKCEWebLoinURL() |
Generates authorization URL with PKCE |
PkceChallenge() |
Generates PKCE code challenge |
GenerateCodeVerifier() |
Generates PKCE code verifier |
GenerateNonce() |
Generates nonce for CSRF protection |
DecodePayload() |
Decodes ID token payload |
DecodeLineProfilePlusPayload() |
Decodes LINE Profile+ payload |
package main
import (
"fmt"
"log"
social "github.com/kkdai/line-login-sdk-go"
)
func main() {
// Initialize client
client, err := social.New("YOUR_CHANNEL_ID", "YOUR_CHANNEL_SECRET")
if err != nil {
log.Fatal(err)
}
// Generate LINE Login URL
loginURL, err := client.GetWebLoinURL(
"https://your-callback-url.com/callback",
"random-state",
"profile openid email",
social.AuthRequestOptions{},
)
if err != nil {
log.Fatal(err)
}
fmt.Println("Login URL:", loginURL)
// After user logs in and you receive the authorization code...
// Exchange code for access token
tokenResponse, err := client.GetAccessToken(
"https://your-callback-url.com/callback",
"AUTHORIZATION_CODE",
).Do()
if err != nil {
log.Fatal(err)
}
fmt.Println("Access Token:", tokenResponse.AccessToken)
// Get user profile
profile, err := client.GetUserProfile(tokenResponse.AccessToken).Do()
if err != nil {
log.Fatal(err)
}
fmt.Println("User ID:", profile.UserID)
fmt.Println("Display Name:", profile.DisplayName)
// Get user info (OIDC)
userInfo, err := client.GetUserInfo(tokenResponse.AccessToken).Do()
if err != nil {
log.Fatal(err)
}
fmt.Println("Sub:", userInfo.Sub)
}// Generate PKCE code verifier and challenge
codeVerifier, err := social.GenerateCodeVerifier(43)
if err != nil {
log.Fatal(err)
}
codeChallenge := social.PkceChallenge(codeVerifier)
// Generate authorization URL with PKCE
loginURL, err := client.GetPKCEWebLoinURL(
"https://your-callback-url.com/callback",
"random-state",
"profile openid",
codeChallenge,
social.AuthRequestOptions{},
)
// Exchange code for token with PKCE
tokenResponse, err := client.GetAccessTokenPKCE(
"https://your-callback-url.com/callback",
"AUTHORIZATION_CODE",
codeVerifier,
).Do()// Revoke all user permissions
// Requires channel access token, not user access token
_, err := client.Deauthorize(channelAccessToken, userAccessToken).Do()
if err != nil {
log.Fatal(err)
}
fmt.Println("User deauthorized successfully")All API calls support Go context for timeout and cancellation:
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
profile, err := client.GetUserProfile(accessToken).WithContext(ctx).Do()Licensed under the Apache License 2.0