Skip to content

Commit

Permalink
Merge pull request #45 from ridi/feature/logic-for-error
Browse files Browse the repository at this point in the history
유저 생성 실패하면 401 에러 리턴
  • Loading branch information
Jeonggeun Kim authored Apr 27, 2020
2 parents 2b307c3 + 1f0ff5d commit afb09c9
Show file tree
Hide file tree
Showing 13 changed files with 102 additions and 109 deletions.
3 changes: 2 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

# F401 imported but unused

ignore=F401
ignore=F401, E722

max-line-length=140

exclude =
./docs
./venv
./tests
migrations
8 changes: 5 additions & 3 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ confidence=
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use"--disable=all --enable=classes

disable=C0111, E0611, C0326, R0903, E0402, W0611, C0103, R0201, W0613, W0614, C0411
disable=C0111, E0611, C0326, R0903, E0402, W0611, C0103, R0201, W0613, W0614, C0411, W0212, W0702, R1705
# C0111 missing-docstring Missing docstring
# E0611 no-name-in-module Missing __init__.py
# C0326 bad-whitespace Check on flake8. pylint dose not support check use spaces around the = sign when used to indicate a keyword argument or a default parameter value.
Expand All @@ -76,9 +76,11 @@ disable=C0111, E0611, C0326, R0903, E0402, W0611, C0103, R0201, W0613, W0614, C0
# C0103 invalid-name
# R0201 no-self-use
# W0613 unused-argument
# C0411 wrong-import-order
# W0614 unused-wildcard-import

# C0411 wrong-import-order
# W0212 protected-access
# W0702 bare-except
# R1705 no-else-return

[REPORTS]

Expand Down
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ jobs:
include:
- stage: test
before_script: make install-dev
script: make lint
script: make test
script:
- make lint
- make test

- stage: deploy
script: skip
Expand Down
5 changes: 3 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
Changelog
=========
1.0.6 (Mar 30th 2020)
1.0.6 (Apr 27th 2020)
------------------
- support 'EC' key_type on JWKS
- Support 'EC' key_type on JWKS
- Add logic to failed in get user object from token_info

1.0.5 (Dec 2nd 2019)
------------------
Expand Down
151 changes: 74 additions & 77 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions ridi_django_oauth2/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
RESPONSE_HANDLER_TYPE = typing.Optional[typing.Callable]


def login_required(response_handler: RESPONSE_HANDLER_TYPE=None):
def login_required(response_handler: RESPONSE_HANDLER_TYPE = None):
def decorator(func):
def wrapper(self, request, *args, **kwargs):
user = request.user
Expand All @@ -25,7 +25,7 @@ def wrapper(self, request, *args, **kwargs):
return decorator


def scope_required(required_scopes: typing.List, response_handler: RESPONSE_HANDLER_TYPE=None):
def scope_required(required_scopes: typing.List, response_handler: RESPONSE_HANDLER_TYPE = None):
def decorator(func):
def wrapper(self, request, *args, **kwargs):
token_info = request.user.token_info
Expand Down
6 changes: 4 additions & 2 deletions ridi_django_oauth2/middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ def process_request(self, request):
return HttpUnauthorizedResponse()

if token_info is not None:
self._set_user_in_request(request, token_info, token)
try:
self._set_user_in_request(request, token_info, token)
except:
return HttpUnauthorizedResponse()

return None

@staticmethod
def _set_user_in_request(request, token_info: AccessTokenInfo, token: TokenData):
get_user_from_token_info = RidiOAuth2Config.get_user_from_token_info_callable()

if get_user_from_token_info:
user = get_user_from_token_info(token_info)

Expand Down
2 changes: 1 addition & 1 deletion ridi_oauth2/client/grant.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def _request_token(self, data: typing.Dict) -> TokenData:
)

@classmethod
def _request(cls, method: str, url: str, data: typing.Dict, headers: typing.Dict=None) -> TokenData:
def _request(cls, method: str, url: str, data: typing.Dict, headers: typing.Dict = None) -> TokenData:
try:
response = requests.request(method=method, url=url, data=data, headers=headers)
response.raise_for_status()
Expand Down
2 changes: 1 addition & 1 deletion ridi_oauth2/introspector/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


class BaseIntrospector:
def __init__(self, access_token: str, token_type_hint: str=None):
def __init__(self, access_token: str, token_type_hint: str = None):
self._access_token = access_token
self._token_type_hint = token_type_hint

Expand Down
8 changes: 0 additions & 8 deletions ridi_oauth2/introspector/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,3 @@ class NotExistedKey(PublicKeyException):

class PublicRequestException(PublicKeyException):
pass


class AccountServerException(PublicRequestException):
pass


class ClientRequestException(PublicRequestException):
pass
11 changes: 4 additions & 7 deletions ridi_oauth2/introspector/key_handler.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from typing import Dict, List

import requests
from requests import RequestException, Response
from requests import Response, HTTPError

from ridi_django_oauth2.config import RidiOAuth2Config
from ridi_django_oauth2_lib.decorators.retry import RetryFailException, retry
from ridi_oauth2.introspector.constants import JWKKeyType, JWKUse
from ridi_oauth2.introspector.dtos import BaseJWKDto
from ridi_oauth2.introspector.exceptions import AccountServerException, ClientRequestException, FailToLoadPublicKeyException, \
from ridi_oauth2.introspector.exceptions import FailToLoadPublicKeyException, \
InvalidPublicKey, NotExistedKey
from ridi_oauth2.introspector.factories import JWKDtoFactory

Expand Down Expand Up @@ -58,14 +58,11 @@ def _memorize_key_dtos(cls, client_id: str, keys: List[BaseJWKDto]):

@staticmethod
def _process_response(response: Response) -> Dict:
if response.status_code >= 500:
raise AccountServerException
elif response.status_code >= 400:
raise ClientRequestException
response.raise_for_status()
return response.json()

@classmethod
@retry(retry_count=3, retriable_exceptions=(RequestException, AccountServerException,))
@retry(retry_count=3, retriable_exceptions=(HTTPError, ))
def _get_valid_public_keys_by_client_id(cls, client_id: str) -> List[BaseJWKDto]:
response = requests.request(
method='GET',
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import find_packages, setup

version = '1.0.5'
version = '1.0.6'

# When the project is installed by pip, this is the specification that is used to install its dependencies.
install_requires = [
Expand Down
4 changes: 2 additions & 2 deletions tests/tests_ridi_django_oauth2/test_token_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

def generate_ec_private_key():
return ec.generate_private_key(
curve=ec.SECP256R1,
backend=default_backend()
curve=ec.SECP256R1,
backend=default_backend()
)


Expand Down

0 comments on commit afb09c9

Please sign in to comment.