https://github.com/iwstkhr/pylwauth
An unofficial library for LINE WORKS Service Account Authentication
https://github.com/iwstkhr/pylwauth
authentication line-works
Last synced: 3 months ago
JSON representation
An unofficial library for LINE WORKS Service Account Authentication
- Host: GitHub
- URL: https://github.com/iwstkhr/pylwauth
- Owner: iwstkhr
- License: mit
- Created: 2022-07-12T18:08:59.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-08-31T16:32:33.000Z (9 months ago)
- Last Synced: 2024-11-09T20:44:09.760Z (6 months ago)
- Topics: authentication, line-works
- Language: Python
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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.```shell
$ pip install git+https://github.com/iwstkhr/pylwauth
``````python
import jsonfrom pylwauth import AuthApi
CLIENT_ID = 'xxxxxxxxxxxxxxxxxxxx'
CLIENT_SECRET = 'xxxxxxxxxx'
SERVICE_ACCOUNT_ID = '[email protected]'
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
# }
```