From c5eb24b8349be7659a87123e792747b1a67cc269 Mon Sep 17 00:00:00 2001 From: Jessica Tallon Date: Tue, 8 Jul 2014 00:02:16 +0100 Subject: Allow crypto.random_string to take optional alphabet param --- mediagoblin/oauth/views.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'mediagoblin/oauth') diff --git a/mediagoblin/oauth/views.py b/mediagoblin/oauth/views.py index 14c8ab14..f424576b 100644 --- a/mediagoblin/oauth/views.py +++ b/mediagoblin/oauth/views.py @@ -15,6 +15,7 @@ # along with this program. If not, see . import datetime +import string from oauthlib.oauth1 import (RequestTokenEndpoint, AuthorizationEndpoint, AccessTokenEndpoint) @@ -35,7 +36,9 @@ from mediagoblin.oauth.tools.forms import WTFormData from mediagoblin.db.models import NonceTimestamp, Client, RequestToken # possible client types -client_types = ["web", "native"] # currently what pump supports +CLIENT_TYPES = ["web", "native"] # currently what pump supports +OAUTH_ALPHABET = (string.ascii_letters.decode('ascii') + + string.digits.decode('ascii')) @csrf_exempt def client_register(request): @@ -53,7 +56,7 @@ def client_register(request): if "type" not in data: error = "No registration type provided." return json_response({"error": error}, status=400) - if data.get("application_type", None) not in client_types: + if data.get("application_type", None) not in CLIENT_TYPES: error = "Unknown application_type." return json_response({"error": error}, status=400) @@ -88,7 +91,7 @@ def client_register(request): ) app_name = ("application_type", client.application_name) - if app_name in client_types: + if app_name in CLIENT_TYPES: client.application_name = app_name elif client_type == "client_associate": @@ -104,8 +107,8 @@ def client_register(request): return json_response({"error": error}, status=400) # generate the client_id and client_secret - client_id = random_string(22) # seems to be what pump uses - client_secret = random_string(43) # again, seems to be what pump uses + client_id = random_string(22, OAUTH_ALPHABET) + client_secret = random_string(43, OAUTH_ALPHABET) expirey = 0 # for now, lets not have it expire expirey_db = None if expirey == 0 else expirey application_type = data["application_type"] -- cgit v1.2.3 From a5682e89602ddc266d05c760a319d7647755f0b4 Mon Sep 17 00:00:00 2001 From: xray7224 Date: Tue, 3 Sep 2013 17:17:07 +0100 Subject: Support some webfinger API's and real profile and /api/user// --- mediagoblin/oauth/routing.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'mediagoblin/oauth') diff --git a/mediagoblin/oauth/routing.py b/mediagoblin/oauth/routing.py index e45077bb..7f2aa11d 100644 --- a/mediagoblin/oauth/routing.py +++ b/mediagoblin/oauth/routing.py @@ -18,25 +18,25 @@ from mediagoblin.tools.routing import add_route # client registration & oauth add_route( - "mediagoblin.oauth", + "mediagoblin.oauth.client_register", "/api/client/register", "mediagoblin.oauth.views:client_register" ) add_route( - "mediagoblin.oauth", + "mediagoblin.oauth.request_token", "/oauth/request_token", "mediagoblin.oauth.views:request_token" ) add_route( - "mediagoblin.oauth", + "mediagoblin.oauth.authorize", "/oauth/authorize", "mediagoblin.oauth.views:authorize", ) add_route( - "mediagoblin.oauth", + "mediagoblin.oauth.access_token", "/oauth/access_token", "mediagoblin.oauth.views:access_token" ) -- cgit v1.2.3 From d4a21d7e746dc1284f44137d1c3e45b7b5ee09c0 Mon Sep 17 00:00:00 2001 From: xray7224 Date: Tue, 24 Sep 2013 20:30:51 +0100 Subject: Add basic upload image capabilities --- mediagoblin/oauth/oauth.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/oauth') diff --git a/mediagoblin/oauth/oauth.py b/mediagoblin/oauth/oauth.py index 8229c47d..d9defa4b 100644 --- a/mediagoblin/oauth/oauth.py +++ b/mediagoblin/oauth/oauth.py @@ -126,7 +126,7 @@ class GMGRequest(Request): """ kwargs["uri"] = kwargs.get("uri", request.url) kwargs["http_method"] = kwargs.get("http_method", request.method) - kwargs["body"] = kwargs.get("body", request.get_data()) + kwargs["body"] = kwargs.get("body", request.data) kwargs["headers"] = kwargs.get("headers", dict(request.headers)) super(GMGRequest, self).__init__(*args, **kwargs) -- cgit v1.2.3 From 6781ff3cb1a26752a0f4bca224813fa374a7f248 Mon Sep 17 00:00:00 2001 From: Jessica Tallon Date: Tue, 8 Jul 2014 21:27:43 +0100 Subject: Clean up & Add support to update objects in feed API --- mediagoblin/oauth/oauth.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'mediagoblin/oauth') diff --git a/mediagoblin/oauth/oauth.py b/mediagoblin/oauth/oauth.py index d9defa4b..8a60392c 100644 --- a/mediagoblin/oauth/oauth.py +++ b/mediagoblin/oauth/oauth.py @@ -15,12 +15,10 @@ # along with this program. If not, see . from oauthlib.common import Request -from oauthlib.oauth1 import RequestValidator +from oauthlib.oauth1 import RequestValidator from mediagoblin.db.models import NonceTimestamp, Client, RequestToken, AccessToken - - class GMGRequestValidator(RequestValidator): enforce_ssl = False @@ -63,14 +61,14 @@ class GMGRequestValidator(RequestValidator): """ Currently a stub - called when making AccessTokens """ return list() - def validate_timestamp_and_nonce(self, client_key, timestamp, - nonce, request, request_token=None, + def validate_timestamp_and_nonce(self, client_key, timestamp, + nonce, request, request_token=None, access_token=None): nc = NonceTimestamp.query.filter_by(timestamp=timestamp, nonce=nonce) nc = nc.first() if nc is None: return True - + return False def validate_client_key(self, client_key, request): @@ -78,7 +76,7 @@ class GMGRequestValidator(RequestValidator): client = Client.query.filter_by(id=client_key).first() if client is None: return False - + return True def validate_access_token(self, client_key, token, request): @@ -119,9 +117,9 @@ class GMGRequest(Request): """ def __init__(self, request, *args, **kwargs): - """ + """ :param request: werkzeug request object - + any extra params are passed to oauthlib.common.Request object """ kwargs["uri"] = kwargs.get("uri", request.url) -- cgit v1.2.3 From 24e12cb133ac7b87094f8c6ec7efa03464ce4474 Mon Sep 17 00:00:00 2001 From: Jessica Tallon Date: Tue, 8 Jul 2014 15:39:24 +0100 Subject: Fix problem in OAuth views --- mediagoblin/oauth/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'mediagoblin/oauth') diff --git a/mediagoblin/oauth/views.py b/mediagoblin/oauth/views.py index f424576b..5ade7a8d 100644 --- a/mediagoblin/oauth/views.py +++ b/mediagoblin/oauth/views.py @@ -252,6 +252,7 @@ def authorize(request): if oauth_request.verifier is None: orequest = GMGRequest(request) + orequest.resource_owner_key = token request_validator = GMGRequestValidator() auth_endpoint = AuthorizationEndpoint(request_validator) verifier = auth_endpoint.create_verifier(orequest, {}) @@ -333,7 +334,7 @@ def access_token(request): error = "Missing required parameter." return json_response({"error": error}, status=400) - + request.resource_owner_key = parsed_tokens["oauth_consumer_key"] request.oauth_token = parsed_tokens["oauth_token"] request_validator = GMGRequestValidator(data) av = AccessTokenEndpoint(request_validator) -- cgit v1.2.3 From 32ff6f4dc06c91d452afa717eb3198cf746c2bf1 Mon Sep 17 00:00:00 2001 From: Jessica Tallon Date: Tue, 5 Aug 2014 21:41:31 +0100 Subject: Use oauthlib's safe characters when generating client_key and client_secret --- mediagoblin/oauth/views.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'mediagoblin/oauth') diff --git a/mediagoblin/oauth/views.py b/mediagoblin/oauth/views.py index 5ade7a8d..641e300a 100644 --- a/mediagoblin/oauth/views.py +++ b/mediagoblin/oauth/views.py @@ -17,6 +17,7 @@ import datetime import string +from oauthlib.oauth1.rfc5849.utils import UNICODE_ASCII_CHARACTER_SET from oauthlib.oauth1 import (RequestTokenEndpoint, AuthorizationEndpoint, AccessTokenEndpoint) @@ -37,8 +38,6 @@ from mediagoblin.db.models import NonceTimestamp, Client, RequestToken # possible client types CLIENT_TYPES = ["web", "native"] # currently what pump supports -OAUTH_ALPHABET = (string.ascii_letters.decode('ascii') + - string.digits.decode('ascii')) @csrf_exempt def client_register(request): @@ -107,8 +106,8 @@ def client_register(request): return json_response({"error": error}, status=400) # generate the client_id and client_secret - client_id = random_string(22, OAUTH_ALPHABET) - client_secret = random_string(43, OAUTH_ALPHABET) + client_id = random_string(22, UNICODE_ASCII_CHARACTER_SET) + client_secret = random_string(43, UNICODE_ASCII_CHARACTER_SET) expirey = 0 # for now, lets not have it expire expirey_db = None if expirey == 0 else expirey application_type = data["application_type"] -- cgit v1.2.3 From 9246a6ba89ab22a07e06b673e9eb0f135d2079a6 Mon Sep 17 00:00:00 2001 From: Jessica Tallon Date: Tue, 5 Aug 2014 22:04:50 +0100 Subject: Tidy up federation code and add tests to cover more of the APIs --- mediagoblin/oauth/views.py | 1 - 1 file changed, 1 deletion(-) (limited to 'mediagoblin/oauth') diff --git a/mediagoblin/oauth/views.py b/mediagoblin/oauth/views.py index 641e300a..90ad5bbf 100644 --- a/mediagoblin/oauth/views.py +++ b/mediagoblin/oauth/views.py @@ -339,4 +339,3 @@ def access_token(request): av = AccessTokenEndpoint(request_validator) tokens = av.create_access_token(request, {}) return form_response(tokens) - -- cgit v1.2.3