Table of Contents
Swit official documentation will guide you through how to implement Swit authentication.
If you have any difficulties in the authentication process with docs, follow this section.
Pyswit will help you.
- Go to Swit developer apps page
- Click
Create App
button on your Apps page - Type your app name and select a workspace
In this doc, I created app and named pyswit
- Click created app and Go to Settings->Authorization page
- In this page, you can see
Client ID
,Client Secret
andRedirect URLs
- At first,
Redirect URLs
is not set. Set it.
In this doc, I set Redirect URLs
to 'https://github.com/sanghunka/pyswit'
- There are two ways
- Run the following script
from pyswit.oauth import Oauth
oauth = Oauth()
oauth.authorize_helper()
oauth.authorize()
- then follow instruction.
state
is an optional parameter.- If you enter your Swit plan(free/standard/advanced) into
scope
, pyswit will set every possible scope. - Or, you can customize scope. (e.g. scope? message:read+message:write)
- The example results are like below.
client_id? rp3lXwXy9HtMtpTk5JIvGqulNBBEjj3f
redirect_uri? https://github.com/sanghunka/pyswit
response_type? [Currently, only 'code' is supported] code
state?
scope? [free/standard/advanced/custom] free
🔗 https://openapi.swit.io/oauth/authorize?client_id=rp3lXwXy9HtMtpTk5JIvGqulNBBEjj3f&redirect_uri=https://github.com/sanghunka/pyswit&response_type=code&state=&scope=channel:read+channel:write+idea:read+idea:write+message:read+message:write+project:read+project:write+task:read+task:write+user:read+workspace:read+workspace:write+approval:read+approval:write
This URL will be redirected to the authentication web page.
Please accept the permission request.
🔗 https://github.com/sanghunka/pyswit?code=<your-code>
Upon confirmation, the user is redirected to this url.
In the query string, <your-code> is authorization code which will be used to exchange for an access token.
- specify parameters in script and run the script
- The rest is the same as above
from pyswit.oauth import Oauth
client_id = <your-client-id>
redirect_url = <your-redirect-url>
scope = <your-scope>
oauth = Oauth(
client_id=client_id,
redirect_uri=redirect_url,
response_type="code",
scope=scope,
)
oauth.authorize()
- Run the following script
- You can get
access_token
andrefresh_token
from pyswit.oauth import Oauth
client_id = <your-client-id>
client_secret = <your-client-secret>
redirect_url = <your-redirect-url>
code = <your-code>
oauth = Oauth(
client_id=client_id, client_secret=client_secret, redirect_uri=redirect_url
)
res = oauth.exchange_for_access_token(code)
print(res)
from pyswit.oauth import Oauth
client_id = <your-client-id>
client_secret = <your-client-secret>
refresh_token = <your-refresh-token>
oauth = Oauth(client_id=client_id, client_secret=client_secret)
res = oauth.refresh_access_token(refresh_token)
print(res)