https://github.com/kkdai/line-login-sdk-go
LINE Login GO SDK (Original Social API SDK, It has been migrated into LINE login 2.1 after 2020/11/12)
https://github.com/kkdai/line-login-sdk-go
golang line line-login-sdk linebot social-api
Last synced: 5 months ago
JSON representation
LINE Login GO SDK (Original Social API SDK, It has been migrated into LINE login 2.1 after 2020/11/12)
- Host: GitHub
- URL: https://github.com/kkdai/line-login-sdk-go
- Owner: kkdai
- License: apache-2.0
- Created: 2019-02-03T17:49:45.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-12-12T05:48:40.000Z (over 1 year ago)
- Last Synced: 2025-04-19T20:17:16.705Z (about 1 year ago)
- Topics: golang, line, line-login-sdk, linebot, social-api
- Language: Go
- Homepage: https://developers.line.biz/en/reference/line-login/
- Size: 50.8 KB
- Stars: 29
- Watchers: 2
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# LINE Login SDK for Go
[](https://raw.githubusercontent.com/kkdai/line-login-sdk-go/master/LICENSE)
[](https://godoc.org/github.com/kkdai/line-login-sdk-go)
[](https://pkg.go.dev/github.com/kkdai/line-login-sdk-go)

[](https://goreportcard.com/report/github.com/kkdai/line-login-sdk-go)
A Go SDK for [LINE Login v2.1 API](https://developers.line.biz/en/reference/line-login/) 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](https://developers.line.biz/en/news/2020/11/12/social-api-is-now-part-of-line-login/).
## Installation
```bash
go get github.com/kkdai/line-login-sdk-go
```
## Supported APIs
### OAuth 2.0 / OpenID Connect
| API | Method | Description |
|-----|--------|-------------|
| [Issue access token](https://developers.line.biz/en/reference/line-login/#issue-access-token) | `GetAccessToken()` | Issues access tokens |
| [Issue access token (PKCE)](https://developers.line.biz/en/docs/line-login/integrate-pkce/) | `GetAccessTokenPKCE()` | Issues access tokens with PKCE |
| [Verify access token](https://developers.line.biz/en/reference/line-login/#verify-access-token) | `TokenVerify()` | Verifies access token validity |
| [Refresh access token](https://developers.line.biz/en/reference/line-login/#refresh-access-token) | `RefreshToken()` | Refreshes access tokens |
| [Revoke access token](https://developers.line.biz/en/reference/line-login/#revoke-access-token) | `RevokeToken()` | Revokes access tokens |
| [Verify ID token](https://developers.line.biz/en/reference/line-login/#verify-id-token) | `VerifyIDToken()` | Verifies ID token authenticity |
### User
| API | Method | Description |
|-----|--------|-------------|
| [Get user profile](https://developers.line.biz/en/reference/line-login/#get-user-profile) | `GetUserProfile()` | Gets user's display name, profile image, and status message |
| [Get user information](https://developers.line.biz/en/reference/line-login/#userinfo) | `GetUserInfo()` | Gets user info via OIDC userinfo endpoint |
| [Get friendship status](https://developers.line.biz/en/reference/line-login/#get-friendship-status) | `GetFriendshipStatus()` | Gets friendship status with LINE Official Account |
### App Management
| API | Method | Description |
|-----|--------|-------------|
| [Deauthorize](https://developers.line.biz/en/reference/line-login/#deauthorize) | `Deauthorize()` | Revokes user permissions (for GDPR compliance) |
### Utility Functions
| 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 |
## Quick Start
```go
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)
}
```
## PKCE Flow Example
```go
// 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()
```
## Deauthorize User (GDPR Compliance)
```go
// 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")
```
## Context Support
All API calls support Go context for timeout and cancellation:
```go
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
profile, err := client.GetUserProfile(accessToken).WithContext(ctx).Do()
```
## License
Licensed under the [Apache License 2.0](LICENSE)