Skip to content

Commit

Permalink
client.updateAuthToken added
Browse files Browse the repository at this point in the history
  • Loading branch information
carpedm20 committed Mar 31, 2015
1 parent 7e17607 commit b5397aa
Show file tree
Hide file tree
Showing 16 changed files with 104 additions and 12 deletions.
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,32 @@ LINE
[![PyPi status](https://pypip.in/status/line/badge.svg?style=flat)](https://pypi.python.org/pypi/line)
[![PyPi license](https://pypip.in/license/line/badge.svg?style=flat)](https://pypi.python.org/pypi/line)

**2014.08.08** Announcement: some codes are removed because of the request of LINE corporation. You can use library only with `authToken` login.

- Documentation : [http://carpedm20.github.io/line/](http://carpedm20.github.io/line/)
- Developer Mailing List: [Google Group](https://groups.google.com/forum/#!forum/line-python-developer)

*May the LINE be with you...*


Update
------

**2015.03.31**

A well-known problem ([issue](https://github.com/carpedm20/LINE/issues/9))of 2 hours authToken expiration that shows `code= 8 reason='EXPIRED'` error is finally SOLVED!

You don't have to change your code because the new code automatically catch the expiration and update the authToken.

But, you can manually update your authToken by:

from line import LineClient, LineGroup, LineContact
client = LineClient("ID", "PASSWORD")
client.updateAuthToken() # manual update

**2014.08.08**

Some codes are removed because of the request of LINE corporation. You can use library only with `authToken` login.


Screenshot
----------

Expand Down
28 changes: 28 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,33 @@ The documentation is available at

*May the LINE be with you...*


Update
------

**2015.03.31**

A well-known problem (`issue`_)of 2 hours authToken expiration that
shows ``code= 8 reason='EXPIRED'`` error is finally SOLVED!

You don’t have to change your code because the new code automatically
catch the expiration and update the authToken.

But, you can manually update your authToken by:

::

from line import LineClient, LineGroup, LineContact
client = LineClient("ID", "PASSWORD")
client.updateAuthToken() # manual update

**2014.08.08**

Some codes are removed because of the request of LINE corporation. You
can use library only with ``authToken`` login.

.. _issue: https://github.com/carpedm20/LINE/issues/9

Screenshot
----------

Expand All @@ -30,3 +57,4 @@ Taehoon Kim / [@carpedm20](http://carpedm20.github.io/about/)
:target: https://pypi.python.org/pypi/line
.. |PyPi license| image:: https://pypip.in/license/line/badge.svg?style=flat
:target: https://pypi.python.org/pypi/line

Binary file modified docs/_build/doctrees/api/api.doctree
Binary file not shown.
Binary file modified docs/_build/doctrees/api/client.doctree
Binary file not shown.
Binary file modified docs/_build/doctrees/api/models.doctree
Binary file not shown.
Binary file modified docs/_build/doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/_build/doctrees/index.doctree
Binary file not shown.
Binary file modified docs/_build/doctrees/issue.doctree
Binary file not shown.
Binary file modified docs/_build/doctrees/tutorial.doctree
Binary file not shown.
9 changes: 8 additions & 1 deletion docs/_build/html/api/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ <h2>LineAPI<a class="headerlink" href="#id1" title="Permalink to this headline">
- mid
- displayNameOverridden
- relation
- <a href="#id2"><span class="problematic" id="id3">thumbnailUrl_</span></a>
- thumbnailUrl
- createdTime
- facoriteTime
- capableMyhome
Expand Down Expand Up @@ -306,6 +306,13 @@ <h2>LineAPI<a class="headerlink" href="#id1" title="Permalink to this headline">
to communicate with LINE server</p>
</dd></dl>

<dl class="method">
<dt id="line.LineAPI.updateAuthToken">
<code class="descname">updateAuthToken</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#line.LineAPI.updateAuthToken" title="Permalink to this definition"></a></dt>
<dd><p>After login, update authToken to avoid expiration of
authToken. This method skip the PinCode validation step.</p>
</dd></dl>

</dd></dl>

</div>
Expand Down
11 changes: 11 additions & 0 deletions docs/_build/html/genindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ <h1 id="index">Index</h1>
| <a href="#L"><strong>L</strong></a>
| <a href="#R"><strong>R</strong></a>
| <a href="#S"><strong>S</strong></a>
| <a href="#U"><strong>U</strong></a>

</div>
<h2 id="_">_</h2>
Expand Down Expand Up @@ -438,6 +439,16 @@ <h2 id="S">S</h2>
<dt><a href="api/models.html#line.LineBase.sendSticker">sendSticker() (line.LineBase method)</a>
</dt>

</dl></td>
</tr></table>

<h2 id="U">U</h2>
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%" valign="top"><dl>

<dt><a href="api/api.html#line.LineAPI.updateAuthToken">updateAuthToken() (line.LineAPI method)</a>
</dt>

</dl></td>
</tr></table>

Expand Down
Binary file modified docs/_build/html/objects.inv
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/_build/html/searchindex.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion line/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from .models import LineGroup, LineContact, LineRoom, LineBase, LineMessage

__copyright__ = 'Copyright 2014 by Taehoon Kim'
__version__ = '0.3.1'
__version__ = '0.4.0'
__license__ = 'BSD'
__author__ = 'Taehoon Kim'
__author_email__ = 'carpedm20@gmail.com'
Expand Down
29 changes: 24 additions & 5 deletions line/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class LineAPI(object):
version = "3.7.0"
com_name = ""
revision = 0
certificate = ""

_session = requests.session()
_headers = {}
Expand All @@ -56,6 +57,19 @@ def ready(self):
"""
raise Exception("Code is removed because of the request of LINE corporation")

def updateAuthToken(self):
"""
After login, update authToken to avoid expiration of
authToken. This method skip the PinCode validation step.
"""
if self.certificate:
self.login()
self.tokenLogin()

return True
else:
self.raise_error("You need to login first. There is no valid certificate")

def tokenLogin(self):
self.transport = THttpClient.THttpClient(self.LINE_HTTP_URL)
self.transport.setCustomHeaders(self._headers)
Expand Down Expand Up @@ -87,15 +101,20 @@ def login(self):

msg = self._client.loginWithIdentityCredentialForCertificate(
self.id, self.password, keyname, crypto, True, self.ip,
self.com_name, self.provider, "")
self.com_name, self.provider, self.certificate)

self._headers['X-Line-Access'] = msg.verifier
self._pinCode = msg.pinCode

print "Enter PinCode '%s' to your mobile phone in 2 minutes"\
% self._pinCode
if msg.type == 3:
print "Enter PinCode '%s' to your mobile phone in 2 minutes"\
% self._pinCode

raise Exception("Code is removed because of the request of LINE corporation")
raise Exception("Code is removed because of the request of LINE corporation")
else:
self.authToken =self._headers['X-Line-Access'] = msg.authToken

return True

def get_json(self, url):
"""Get josn from given url with saved session and headers"""
Expand Down Expand Up @@ -142,7 +161,7 @@ def _getContacts(self, ids):
- mid
- displayNameOverridden
- relation
- thumbnailUrl_
- thumbnailUrl
- createdTime
- facoriteTime
- capableMyhome
Expand Down
13 changes: 11 additions & 2 deletions line/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,16 @@ def sendMessage(self, message, seq=0):
:param message: LineMessage instance to send
"""
if self._check_auth():
self._sendMessage(message, seq)
try:
self._sendMessage(message, seq)
except TalkException as e:
self.refreshAuthToken()
try:
self._sendMessage(message, seq)
except Exception as e:
self.raise_error(e)

return False

def getMessageBox(self, id):
"""Get MessageBox by id
Expand Down Expand Up @@ -495,7 +504,7 @@ def longPoll(self, count=50):
return
except TalkException as e:
if e.code == 9:
self.raise_error("user logged in to another machien")
self.raise_error("user logged in to another machine")
else:
return

Expand Down

0 comments on commit b5397aa

Please sign in to comment.