-
Notifications
You must be signed in to change notification settings - Fork 1k
Support OAuth #174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Support OAuth #174
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4a3b02b
support OAuth
okue a66a725
fix typo and refactor
okue e539133
fix typo in README
okue 4f80de2
fix
okue 2bbf5f6
add test
okue b4785b4
small change
okue 502d2f0
fix style error
okue 31e0a5a
rename
okue 8824866
modify pydoc
okue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
from __future__ import unicode_literals, absolute_import | ||
|
||
import sys | ||
import unittest | ||
|
||
import responses | ||
|
||
from linebot import ( | ||
LineBotApi | ||
) | ||
|
||
PY3 = sys.version_info[0] == 3 | ||
if PY3: | ||
from urllib import parse | ||
else: | ||
import urlparse as parse | ||
|
||
|
||
class TestLineBotApi(unittest.TestCase): | ||
def setUp(self): | ||
self.tested = LineBotApi('channel_secret') | ||
self.endpoint = LineBotApi.DEFAULT_API_ENDPOINT + '/v2/oauth/accessToken' | ||
self.access_token = "W1TeHCgfH2Liwa....." | ||
self.expires_in = 2592000 | ||
self.token_type = "Bearer" | ||
self.client_id = 'client_id' | ||
self.client_secret = 'client_secret' | ||
|
||
@responses.activate | ||
def test_issue_line_token(self): | ||
responses.add( | ||
responses.POST, | ||
self.endpoint, | ||
json={ | ||
"access_token": self.access_token, | ||
"expires_in": self.expires_in, | ||
"token_type": self.token_type | ||
}, | ||
status=200 | ||
) | ||
|
||
issue_access_token_response = self.tested.issue_channel_token( | ||
self.client_id, | ||
self.client_secret | ||
) | ||
|
||
request = responses.calls[0].request | ||
self.assertEqual('POST', request.method) | ||
self.assertEqual(self.endpoint, request.url) | ||
self.assertEqual('application/x-www-form-urlencoded', request.headers['content-type']) | ||
self.assertEqual(self.access_token, issue_access_token_response.access_token) | ||
self.assertEqual(self.expires_in, issue_access_token_response.expires_in) | ||
self.assertEqual(self.token_type, issue_access_token_response.token_type) | ||
|
||
encoded_body = parse.parse_qs(request.body) | ||
self.assertEqual('client_credentials', encoded_body['grant_type'][0]) | ||
self.assertEqual(self.client_id, encoded_body['client_id'][0]) | ||
self.assertEqual(self.client_secret, encoded_body['client_secret'][0]) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
from __future__ import unicode_literals, absolute_import | ||
|
||
import unittest | ||
|
||
import responses | ||
|
||
from linebot import ( | ||
LineBotApi | ||
) | ||
|
||
|
||
class TestLineBotApi(unittest.TestCase): | ||
def setUp(self): | ||
self.tested = LineBotApi('channel_secret') | ||
self.endpoint = LineBotApi.DEFAULT_API_ENDPOINT + '/v2/oauth/revoke' | ||
self.access_token = "W1TeHCgfH2Liwa....." | ||
|
||
@responses.activate | ||
def test_issue_line_token(self): | ||
responses.add( | ||
responses.POST, | ||
self.endpoint, | ||
status=200 | ||
) | ||
|
||
self.tested.revoke_channel_token(self.access_token) | ||
|
||
request = responses.calls[0].request | ||
self.assertEqual('POST', request.method) | ||
self.assertEqual(self.endpoint, request.url) | ||
self.assertEqual('application/x-www-form-urlencoded', request.headers['content-type']) | ||
self.assertEqual('access_token={}'.format(self.access_token), request.body) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.