forked from twilio/authy-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial commit. slightly borrowed from twilio client
Signed-off-by: David A. Cuadrado <[email protected]>
- Loading branch information
0 parents
commit 8d8cea4
Showing
19 changed files
with
3,521 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,6 @@ | ||
build | ||
dist | ||
docs/tmp | ||
docs/build | ||
*.tmproj | ||
*.py[co] |
This file contains 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,10 @@ | ||
python-authy Changelog | ||
======================= | ||
|
||
Here you can see the full list of changes between each python-authy release. | ||
|
||
Version 0.0.1 | ||
------------- | ||
|
||
- Initial version | ||
|
This file contains 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,22 @@ | ||
Copyright (c) 2012 Authy, Inc. | ||
|
||
Permission is hereby granted, free of charge, to any person | ||
obtaining a copy of this software and associated documentation | ||
files (the "Software"), to deal in the Software without | ||
restriction, including without limitation the rights to use, | ||
copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following | ||
conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. |
Empty file.
This file contains 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,18 @@ | ||
__version_info__ = ('0', '0', '1') | ||
__version__ = '.'.join(__version_info__) | ||
|
||
|
||
class AuthyException(Exception): | ||
pass | ||
|
||
|
||
class AuthyApiException(AuthyException): | ||
|
||
def __init__(self, status, uri, msg=""): | ||
self.uri = uri | ||
self.status = status | ||
self.msg = msg | ||
|
||
def __str__(self): | ||
return "HTTP ERROR %s: %s \n %s" % (self.status, self.msg, self.uri) | ||
|
This file contains 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,22 @@ | ||
import logging | ||
import os | ||
from authy import AuthyException | ||
from authy.api.resources import Users | ||
from authy.api.resources import Tokens | ||
|
||
from urllib import urlencode | ||
from urlparse import urljoin | ||
|
||
|
||
class AuthyApiClient(object): | ||
""" | ||
A client for accessing the Authy REST API | ||
""" | ||
def __init__(self, api_key, api_uri="https://api.authy.com"): | ||
""" | ||
Create a Authy REST API client. | ||
""" | ||
self.api_uri = api_uri | ||
self.users = Users(api_uri, api_key) | ||
self.tokens = Tokens(api_uri, api_key) | ||
self.api_key = api_key |
This file contains 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,88 @@ | ||
import re | ||
import datetime | ||
import logging | ||
import authy | ||
from authy import AuthyException | ||
from authy import AuthyApiException | ||
from urllib import urlencode | ||
from urlparse import urlparse | ||
|
||
# import json | ||
try: | ||
import json | ||
except ImportError: | ||
try: | ||
import simplejson as json | ||
except ImportError: | ||
from django.utils import simplejson as json | ||
|
||
# import httplib2 | ||
try: | ||
import httplib2 | ||
except ImportError: | ||
from authy.contrib import httplib2 | ||
|
||
|
||
class Resource(object): | ||
def __init__(self, api_uri, api_key): | ||
self.api_uri = api_uri | ||
self.api_key = api_key | ||
|
||
def post(self, path, data = {}): | ||
return self.request("POST", path, data, {'Content-Type': 'application/json'}) | ||
|
||
def get(self, path): | ||
return self.request("GET", path) | ||
|
||
def put(self, path, data = {}): | ||
return self.request("PUT", path, data, {'Content-Type': 'application/json'}) | ||
|
||
def delete(self, path): | ||
return self.request("DELETE", path, data) | ||
|
||
def request(self, method, path, data = {}, headers = {}): | ||
http = httplib2.Http() | ||
http.follow_redirects = True | ||
|
||
body = json.dumps(data) | ||
|
||
url = self.api_uri + path + "?api_key="+self.api_key | ||
return http.request(url, method, headers=headers, body=body) | ||
|
||
class Instance(object): | ||
def __init__(self, resource, response, content): | ||
self.resource = resource | ||
self.response = response | ||
|
||
try: | ||
self.content = json.loads(content) | ||
except ValueError: | ||
self.content = content | ||
|
||
def ok(self): | ||
return self.response['status'] == '200' | ||
|
||
|
||
class User(Instance): | ||
pass | ||
|
||
class Users(Resource): | ||
def create(self, email, phone): | ||
data = { | ||
"user": { | ||
"email": email, | ||
"phone": phone | ||
} | ||
} | ||
|
||
resp, content = self.post("/protected/json/users/new", data) | ||
|
||
return User(self, resp, content) | ||
|
||
class Token(Instance): | ||
pass | ||
|
||
class Tokens(Resource): | ||
def verify(self, device_id, token): | ||
resp, content = self.get("/protected/json/verify/"+token+"/"+str(device_id)+"?api_key="+self.api_key) | ||
return Token(self, resp, content) |
Empty file.
Oops, something went wrong.