iwstkhr / pylwauth

An unofficial library for LINE WORKS Service Account Authentication

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pylwauth

An unofficial library for LINE WORKS Service Account Authentication (API 2.0)

https://developers.worksmobile.com/jp/reference/authorization-sa

Usage

This library cannot be installed through PyPI for now.

$ pip install git+https://github.com/iwstkhr/pylwauth
import json

from pylwauth import AuthApi

CLIENT_ID = 'xxxxxxxxxxxxxxxxxxxx'
CLIENT_SECRET = 'xxxxxxxxxx'
SERVICE_ACCOUNT_ID = 'your-service-account@xxx.yy.zz'
PRIVATE_KEY = '''-----BEGIN PRIVATE KEY-----
YOUR PRIVATE KEY
-----END PRIVATE KEY-----'''

api = AuthApi(CLIENT_ID, CLIENT_SECRET, SERVICE_ACCOUNT_ID, PRIVATE_KEY)

# Get an access token.
token = api.get_token(scope='user.read, orgunit.read, bot')
print(json.dumps(token.to_dict(), indent=2))

# {
#   "access_token": "xxxxxxxxxx",
#   "refresh_token": "xxxxxxxxxx",
#   "expires_in": 86400,
#   "scope": "user.read,orgunit.read,bot",
#   "expired_at": 1657732563
# }

# Refresh the token.
# Note that in service account authentication it may be secure to get another access token
# rather than refresh the existing one, because the refresh token is kept alive in 90 days.
token = api.refresh_token(token.refresh_token)
print(json.dumps(token.to_dict(), indent=2))

# {
#   "access_token": "xxxxxxxxxx",
#   "refresh_token": null,
#   "expires_in": 86400,
#   "scope": "user.read,orgunit.read,bot",
#   "expired_at": 1657733553
# }

About

An unofficial library for LINE WORKS Service Account Authentication

License:MIT License


Languages

Language:Python 100.0%