Commit a12b8a15 authored by Sofia Papagiannaki's avatar Sofia Papagiannaki

astakos oa2: rename settings and url prefixes

Change setting and url prefixes from `oa2` to 
`oauth2`
parent 6cf05061
......@@ -145,16 +145,17 @@ class AstakosClient(object):
self._ui_prefix = parsed_ui_url.path
self.logger.debug("Got ui_prefix \"%s\"" % self._ui_prefix)
oa2_service_catalog = parse_endpoints(endpoints, ep_name="astakos_oa2")
self._oa2_url = \
oa2_service_catalog[0]['endpoints'][0]['publicURL']
parsed_oa2_url = urlparse.urlparse(self._oa2_url)
self._oa2_prefix = parsed_oa2_url.path
oauth2_service_catalog = parse_endpoints(endpoints,
ep_name="astakos_oauth2")
self._oauth2_url = \
oauth2_service_catalog[0]['endpoints'][0]['publicURL']
parsed_oauth2_url = urlparse.urlparse(self._oauth2_url)
self._oauth2_prefix = parsed_oauth2_url.path
def _get_value(self, s):
assert s in ['_account_url', '_account_prefix',
'_ui_url', '_ui_prefix',
'_oa2_url', '_oa2_prefix']
'_oauth2_url', '_oauth2_prefix']
try:
return getattr(self, s)
except AttributeError:
......@@ -178,12 +179,12 @@ class AstakosClient(object):
return self._get_value('_ui_prefix')
@property
def oa2_url(self):
return self._get_value('_oa2_url')
def oauth2_url(self):
return self._get_value('_oauth2_url')
@property
def oa2_prefix(self):
return self._get_value('_oa2_prefix')
def oauth2_prefix(self):
return self._get_value('_oauth2_prefix')
@property
def api_usercatalogs(self):
......@@ -234,12 +235,12 @@ class AstakosClient(object):
return join_urls(self.ui_prefix, "get_services")
@property
def api_oa2_auth(self):
return join_urls(self.oa2_prefix, "auth")
def api_oauth2_auth(self):
return join_urls(self.oauth2_prefix, "auth")
@property
def api_oa2_token(self):
return join_urls(self.oa2_prefix, "token")
def api_oauth2_token(self):
return join_urls(self.oauth2_prefix, "token")
# ----------------------------------
@retry_dec
......@@ -925,7 +926,7 @@ class AstakosClient(object):
body=req_body, method="POST")
# --------------------------------
# do a POST to ``API_OA2_TOKEN``
# do a POST to ``API_OAUTH2_TOKEN``
def get_token(self, grant_type, client_id, client_secret, **body_params):
headers = {'content-type': 'application/x-www-form-urlencoded',
'Authorization': 'Basic %s' % b64encode('%s:%s' %
......@@ -933,7 +934,7 @@ class AstakosClient(object):
client_secret))}
body_params['grant_type'] = grant_type
body = urllib.urlencode(body_params)
return self._call_astakos(self.api_oa2_token, headers=headers,
return self._call_astakos(self.api_oauth2_token, headers=headers,
body=body, method="POST")
......
......@@ -197,7 +197,7 @@ class SimpleBackend(object):
__metaclass__ = BackendBase
base_url = ''
endpoints_prefix = 'oa2/'
endpoints_prefix = 'oauth2/'
token_endpoint = 'token/'
token_length = 30
......@@ -217,7 +217,7 @@ class SimpleBackend(object):
code_model = AuthorizationCode
user_model = User
def __init__(self, base_url='', endpoints_prefix='oa2/', id='oa2',
def __init__(self, base_url='', endpoints_prefix='oauth2/', id='oauth2',
token_endpoint='token/', token_length=30,
token_expires=20, authorization_endpoint='auth/',
authorization_code_length=60, **kwargs):
......
......@@ -32,11 +32,13 @@
# or implied, of GRNET S.A.
from astakos.oa2 import settings
oa2_services = {
'astakos_oa2': {
'astakos_oauth2': {
'type': 'astakos_auth',
'component': 'astakos',
'prefix': 'oa2',
'prefix': settings.ENDPOINT_PREFIX,
'public': True,
'endpoints': [
{'versionId': '',
......
......@@ -2,11 +2,11 @@ from django.conf import settings
def get_setting(key, default):
return getattr(settings, 'OA2_%s' % key, default)
return getattr(settings, 'OAUTH2_%s' % key, default)
USER_MODEL = get_setting('USER_MODEL', 'auth.User')
ENDPOINT_PREFIX = get_setting('ENDPOINT_PREFIX', 'oa2/')
ENDPOINT_PREFIX = get_setting('ENDPOINT_PREFIX', 'oauth2/')
TOKEN_ENDPOINT = get_setting('TOKEN_ENDPOINT', 'token/')
......
#USER_MODEL = get_setting('USER_MODEL', 'auth.User')
#OAUTH2_USER_MODEL = 'auth.User'
#
#ENDPOINT_PREFIX = get_setting('ENDPOINT_PREFIX', 'oa2/')
#OAUTH2_ENDPOINT_PREFIX = 'oa2/'
#
#TOKEN_ENDPOINT = get_setting('TOKEN_ENDPOINT', 'token/')
#OAUTH2_TOKEN_ENDPOINT = 'token/'
#
#AUTHORIZATION_ENDPOINT = get_setting('AUTHORIZATION_ENDPOINT', 'auth/')
#OAUTH2_AUTHORIZATION_ENDPOINT = 'auth/'
#
## Set the length of newly created authorization codes to 60 characters
#AUTHORIZATION_CODE_LENGTH = get_setting('AUTHORIZATION_CODE_LENGTH', 60)
#OAUTH2_AUTHORIZATION_CODE_LENGTH = 60
#
## Set the length of newly created access tokens to 30 characters
#TOKEN_LENGTH = get_setting('TOKEN_LENGTH', 30)
#OAUTH2_TOKEN_LENGTH = 30
#
## Set the expiration time of newly created access tokens to 20 seconds
#TOKEN_EXPIRES = get_setting('TOKEN_EXPIRES', 20)
#OAUTH2_TOKEN_EXPIRES = 20
......@@ -91,3 +91,16 @@ ASTAKOS_COMPONENTS_META = {
}
}
OAUTH2_USER_MODEL = 'auth.User'
OAUTH2_ENDPOINT_PREFIX = 'oauth2/'
OAUTH2_TOKEN_ENDPOINT = 'token/'
OAUTH2_AUTHORIZATION_ENDPOINT = 'auth/'
OAUTH2_AUTHORIZATION_CODE_LENGTH = 60
OAUTH2_TOKEN_LENGTH = 30
OAUTH2_TOKEN_EXPIRES = 20
......@@ -58,10 +58,9 @@
# Extra requests will be blocked until another has completed.
#PITHOS_BACKEND_POOL_SIZE = 5
#
# Set the credentials (client_id, client_secret) issued to authenticate
# Set the credentials (client_id, client_secret) issued for authenticating
# the views with astakos during the resource access token generation procedure
#OA2_CLIENT_CREDENTIALS = getattr(settings, 'PITHOS_OA2_CLIENT_CREDENTIALS',
# (None, None))
#PITHOS_OAUTH2_CLIENT_CREDENTIALS = (None, None)
#
# Set to False to serve only views
#SERVE_API = getattr(settings, 'PITHOS_SERVE_API', True)
......@@ -184,13 +184,11 @@ BACKEND_BLOCK_SIZE = getattr(
BACKEND_HASH_ALGORITHM = getattr(
settings, 'PITHOS_BACKEND_HASH_ALGORITHM', 'sha256')
# Set the credentials (client_id, client_secret) issued to authenticate
# Set the credentials (client_id, client_secret) issued for authenticating
# the views with astakos during the resource access token generation procedure
OA2_CLIENT_CREDENTIALS = getattr(settings, 'PITHOS_OA2_CLIENT_CREDENTIALS',
(None, None))
# Set to False to disable serving object content serving endpoints
SERVE_API = getattr(settings, 'PITHOS_SERVE_API', True)
OAUTH2_CLIENT_CREDENTIALS = getattr(settings,
'PITHOS_OAUTH2_CLIENT_CREDENTIALS',
(None, None))
# Set domain to restrict requests of pithos object contents serve endpoint or
# None for no domain restriction
......
......@@ -67,7 +67,7 @@ from pithos.api.settings import (BACKEND_DB_MODULE, BACKEND_DB_CONNECTION,
RADOS_POOL_MAPS, TRANSLATE_UUIDS,
PUBLIC_URL_SECURITY, PUBLIC_URL_ALPHABET,
BASE_HOST, UPDATE_MD5, VIEW_PREFIX,
OA2_CLIENT_CREDENTIALS, SERVE_API_DOMAIN)
OAUTH2_CLIENT_CREDENTIALS, SERVE_API_DOMAIN)
from pithos.api.resources import resources
from pithos.backends import connect_backend
......@@ -1195,7 +1195,7 @@ def view_method():
raise PermissionDenied
return response
client_id, client_secret = OA2_CLIENT_CREDENTIALS
client_id, client_secret = OAUTH2_CLIENT_CREDENTIALS
# TODO: check if client credentials are not set
authorization_code = request.GET.get('code')
if authorization_code is None:
......@@ -1207,7 +1207,7 @@ def view_method():
'state': '', # TODO include state for security
'scope': request.path.split(VIEW_PREFIX, 2)[-1]}
return HttpResponseRedirect('%s?%s' %
(join_urls(astakos.oa2_url,
(join_urls(astakos.oauth2_url,
'auth'),
urlencode(params)))
else:
......@@ -1223,7 +1223,7 @@ def view_method():
redirect_uri = '%s%s' % (redirect_host, request.path)
data = astakos.get_token('authorization_code',
*OA2_CLIENT_CREDENTIALS,
*OAUTH2_CLIENT_CREDENTIALS,
redirect_uri=redirect_uri,
scope=requested_resource,
code=authorization_code)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment