|
14 | 14 |
|
15 | 15 | """linebot.api module."""
|
16 | 16 |
|
17 |
| - |
18 | 17 | import json
|
19 | 18 |
|
20 | 19 | from .__about__ import __version__
|
|
31 | 30 | AudienceGroup, ClickAudienceGroup, ImpAudienceGroup, GetAuthorityLevel, Audience,
|
32 | 31 | CreateAudienceGroup
|
33 | 32 | )
|
34 |
| -from .models.responses import Group, UserIds, RichMenuAliasResponse, RichMenuAliasListResponse |
| 33 | +from .models.responses import ( |
| 34 | + Group, UserIds, RichMenuAliasResponse, RichMenuAliasListResponse, ChannelAccessTokens, |
| 35 | + IssueChannelTokenResponseV2, VerifyChannelTokenResponseV2, ValidAccessTokenKeyIDsResponse |
| 36 | +) |
35 | 37 |
|
36 | 38 |
|
37 | 39 | class LineBotApi(object):
|
@@ -1594,6 +1596,128 @@ def get_followers_ids(self, limit=300, start=None, timeout=None):
|
1594 | 1596 |
|
1595 | 1597 | return UserIds.new_from_json_dict(response.json)
|
1596 | 1598 |
|
| 1599 | + def issue_channel_access_token_v2_1( |
| 1600 | + self, client_assertion, grant_type='client_credentials', |
| 1601 | + client_assertion_type='urn:ietf:params:oauth:client-assertion-type:jwt-bearer', |
| 1602 | + timeout=None): |
| 1603 | + """Issues a channel access token v2.1. |
| 1604 | +
|
| 1605 | + https://developers.line.biz/en/reference/messaging-api/#issue-channel-access-token-v2-1 |
| 1606 | +
|
| 1607 | + :param str client_assertion: Client assertion. |
| 1608 | + :param str grant_type: `client_credentials` |
| 1609 | + :param str client_assertion_type: `urn:ietf:params:oauth:client-assertion-type:jwt-bearer`. |
| 1610 | + :param timeout: (optional) How long to wait for the server |
| 1611 | + to send data before giving up, as a float, |
| 1612 | + or a (connect timeout, read timeout) float tuple. |
| 1613 | + Default is self.http_client.timeout |
| 1614 | + :type timeout: float | tuple(float, float) |
| 1615 | + :rtype: :py:class:`linebot.models.responses.IssueChannelTokenResponseV2` |
| 1616 | + """ |
| 1617 | + response = self._post( |
| 1618 | + '/oauth2/v2.1/token', |
| 1619 | + data={ |
| 1620 | + 'grant_type': grant_type, |
| 1621 | + 'client_assertion_type': client_assertion_type, |
| 1622 | + 'client_assertion': client_assertion, |
| 1623 | + }, |
| 1624 | + headers={'Content-Type': 'application/x-www-form-urlencoded'}, |
| 1625 | + timeout=timeout |
| 1626 | + ) |
| 1627 | + |
| 1628 | + return IssueChannelTokenResponseV2.new_from_json_dict(response.json) |
| 1629 | + |
| 1630 | + def revoke_channel_access_token_v2_1( |
| 1631 | + self, client_id, |
| 1632 | + client_secret, access_token, |
| 1633 | + timeout=None): |
| 1634 | + """Revokes a channel access token v2.1. |
| 1635 | +
|
| 1636 | + https://developers.line.biz/en/reference/messaging-api/#revoke-channel-access-token-v2-1 |
| 1637 | +
|
| 1638 | + :param str client_id: Client id. |
| 1639 | + :param str client_secret: Channel secret. |
| 1640 | + :param str access_token: Channel access token. |
| 1641 | + :param timeout: (optional) How long to wait for the server |
| 1642 | + to send data before giving up, as a float, |
| 1643 | + or a (connect timeout, read timeout) float tuple. |
| 1644 | + Default is self.http_client.timeout |
| 1645 | + :type timeout: float | tuple(float, float) |
| 1646 | + """ |
| 1647 | + self._post( |
| 1648 | + '/oauth2/v2.1/revoke', |
| 1649 | + data={'client_id': client_id, |
| 1650 | + 'client_secret': client_secret, |
| 1651 | + 'access_token': access_token}, |
| 1652 | + timeout=timeout |
| 1653 | + ) |
| 1654 | + |
| 1655 | + def get_channel_access_tokens_v2_1( |
| 1656 | + self, client_assertion, |
| 1657 | + client_assertion_type='urn:ietf:params:oauth:client-assertion-type:jwt-bearer', |
| 1658 | + timeout=None): |
| 1659 | + """Get issued channel access tokens v2.1. |
| 1660 | +
|
| 1661 | + https://developers.line.biz/en/reference/messaging-api/#get-issued-channel-access-tokens-v2-1 |
| 1662 | +
|
| 1663 | + :param str client_assertion: Client assertion. |
| 1664 | + :param str client_assertion_type: `urn:ietf:params:oauth:client-assertion-type:jwt-bearer`. |
| 1665 | + :param timeout: (optional) How long to wait for the server |
| 1666 | + to send data before giving up, as a float, |
| 1667 | + or a (connect timeout, read timeout) float tuple. |
| 1668 | + Default is self.http_client.timeout |
| 1669 | + :type timeout: float | tuple(float, float) |
| 1670 | + :rtype: :py:class:`linebot.models.responses.ChannelAccessTokens` |
| 1671 | + """ |
| 1672 | + response = self._get( |
| 1673 | + '/oauth2/v2.1/tokens', |
| 1674 | + params={'client_assertion': client_assertion, |
| 1675 | + 'client_assertion_type': client_assertion_type}, |
| 1676 | + timeout=timeout |
| 1677 | + ) |
| 1678 | + return ChannelAccessTokens.new_from_json_dict(response.json) |
| 1679 | + |
| 1680 | + def verify_channel_access_token_v2_1(self, access_token, timeout=None): |
| 1681 | + """Validate channel access token v2.1. |
| 1682 | +
|
| 1683 | + https://developers.line.biz/en/reference/messaging-api/#verfiy-channel-access-token-v2-1 |
| 1684 | +
|
| 1685 | + :param str access_token: Channel access token. |
| 1686 | + :param timeout: (optional) How long to wait for the server |
| 1687 | + to send data before giving up, as a float, |
| 1688 | + or a (connect timeout, read timeout) float tuple. |
| 1689 | + Default is self.http_client.timeout |
| 1690 | + :type timeout: float | tuple(float, float) |
| 1691 | + :rtype: :py:class:`linebot.models.responses.VerifyChannelTokenResponseV2` |
| 1692 | + """ |
| 1693 | + response = self._get('/oauth2/v2.1/verify', |
| 1694 | + params={'access_token': access_token}, |
| 1695 | + timeout=timeout) |
| 1696 | + return VerifyChannelTokenResponseV2.new_from_json_dict(response.json) |
| 1697 | + |
| 1698 | + def get_channel_token_key_ids_v2_1( |
| 1699 | + self, client_assertion, |
| 1700 | + client_assertion_type='urn:ietf:params:oauth:client-assertion-type:jwt-bearer', |
| 1701 | + timeout=None): |
| 1702 | + """Get all valid channel access token key IDs v2.1. |
| 1703 | +
|
| 1704 | + https://developers.line.biz/en/reference/messaging-api/#get-all-valid-channel-access-token-key-ids-v2-1 |
| 1705 | +
|
| 1706 | + :param str client_assertion: Client assertion. |
| 1707 | + :param str client_assertion_type: `urn:ietf:params:oauth:client-assertion-type:jwt-bearer`. |
| 1708 | + :param timeout: (optional) How long to wait for the server |
| 1709 | + to send data before giving up, as a float, |
| 1710 | + or a (connect timeout, read timeout) float tuple. |
| 1711 | + Default is self.http_client.timeout |
| 1712 | + :type timeout: float | tuple(float, float) |
| 1713 | + :rtype: :py:class:`linebot.models.responses.VerifyChannelTokenResponseV2` |
| 1714 | + """ |
| 1715 | + response = self._get('/oauth2/v2.1/tokens/kid', |
| 1716 | + params={"client_assertion": client_assertion, |
| 1717 | + "client_assertion_type": client_assertion_type}, |
| 1718 | + timeout=timeout) |
| 1719 | + return ValidAccessTokenKeyIDsResponse.new_from_json_dict(response.json) |
| 1720 | + |
1597 | 1721 | def _get(self, path, endpoint=None, params=None, headers=None, stream=False, timeout=None):
|
1598 | 1722 | url = (endpoint or self.endpoint) + path
|
1599 | 1723 |
|
|
0 commit comments