Thanks to visit codestin.com
Credit goes to github.com

Skip to content

OpenID Connect split #525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jun 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,27 @@
# Since these contacts will be addressed with Github mentions they
# need to be Github users (for now)(sorry Bitbucket).
#
clean:
clean: clean-eggs clean-build
@find . -iname '*.pyc' -delete
@find . -iname '*.pyo' -delete
@find . -iname '*~' -delete
@find . -iname '*.swp' -delete
@find . -iname '__pycache__' -delete
rm -rf .tox
rm -rf bottle-oauthlib
rm -rf django-oauth-toolkit
rm -rf flask-oauthlib
rm -rf requests-oauthlib

clean-eggs:
@find . -name '*.egg' -print0|xargs -0 rm -rf --
@rm -rf .eggs/

clean-build:
@rm -fr build/
@rm -fr dist/
@rm -fr *.egg-info

test:
tox

Expand Down Expand Up @@ -51,7 +65,6 @@ requests:
cd requests-oauthlib 2>/dev/null || git clone https://github.com/requests/requests-oauthlib.git
cd requests-oauthlib && sed -i.old 's,deps=,deps = --editable=file://{toxinidir}/../[signedtoken],' tox.ini && sed -i.old '/oauthlib/d' requirements.txt && tox


.DEFAULT_GOAL := all
.PHONY: clean test bottle django flask requests
all: clean test bottle django flask requests
2 changes: 1 addition & 1 deletion oauthlib/oauth2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from .rfc6749.endpoints import MobileApplicationServer
from .rfc6749.endpoints import LegacyApplicationServer
from .rfc6749.endpoints import BackendApplicationServer
from .rfc6749.errors import AccessDeniedError, AccountSelectionRequired, ConsentRequired, FatalClientError, FatalOpenIDClientError, InsecureTransportError, InteractionRequired, InvalidClientError, InvalidClientIdError, InvalidGrantError, InvalidRedirectURIError, InvalidRequestError, InvalidRequestFatalError, InvalidScopeError, LoginRequired, MismatchingRedirectURIError, MismatchingStateError, MissingClientIdError, MissingCodeError, MissingRedirectURIError, MissingResponseTypeError, MissingTokenError, MissingTokenTypeError, OAuth2Error, OpenIDClientError, ServerError, TemporarilyUnavailableError, TokenExpiredError, UnauthorizedClientError, UnsupportedGrantTypeError, UnsupportedResponseTypeError, UnsupportedTokenTypeError
from .rfc6749.errors import AccessDeniedError, OAuth2Error, FatalClientError, InsecureTransportError, InvalidClientError, InvalidClientIdError, InvalidGrantError, InvalidRedirectURIError, InvalidRequestError, InvalidRequestFatalError, InvalidScopeError, MismatchingRedirectURIError, MismatchingStateError, MissingClientIdError, MissingCodeError, MissingRedirectURIError, MissingResponseTypeError, MissingTokenError, MissingTokenTypeError, ServerError, TemporarilyUnavailableError, TokenExpiredError, UnauthorizedClientError, UnsupportedGrantTypeError, UnsupportedResponseTypeError, UnsupportedTokenTypeError
from .rfc6749.grant_types import AuthorizationCodeGrant
from .rfc6749.grant_types import ImplicitGrant
from .rfc6749.grant_types import ResourceOwnerPasswordCredentialsGrant
Expand Down
43 changes: 11 additions & 32 deletions oauthlib/oauth2/rfc6749/endpoints/pre_configured.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
# -*- coding: utf-8 -*-
"""
oauthlib.oauth2.rfc6749
~~~~~~~~~~~~~~~~~~~~~~~
oauthlib.oauth2.rfc6749.endpoints.pre_configured
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This module is an implementation of various logic needed
for consuming and providing OAuth 2.0 RFC6749.
This module is an implementation of various endpoints needed
for providing OAuth 2.0 RFC6749 servers.
"""
from __future__ import absolute_import, unicode_literals

from ..grant_types import (AuthCodeGrantDispatcher, AuthorizationCodeGrant,
AuthTokenGrantDispatcher,
from ..grant_types import (AuthorizationCodeGrant,
ClientCredentialsGrant,
ImplicitTokenGrantDispatcher, ImplicitGrant,
OpenIDConnectAuthCode, OpenIDConnectImplicit,
OpenIDConnectHybrid,
ImplicitGrant,
RefreshTokenGrant,
ResourceOwnerPasswordCredentialsGrant)
from ..tokens import BearerToken, JWTToken
from ..tokens import BearerToken
from .authorization import AuthorizationEndpoint
from .introspect import IntrospectEndpoint
from .resource import ResourceEndpoint
Expand Down Expand Up @@ -51,46 +48,28 @@ def __init__(self, request_validator, token_expires_in=None,
request_validator)
credentials_grant = ClientCredentialsGrant(request_validator)
refresh_grant = RefreshTokenGrant(request_validator)
openid_connect_auth = OpenIDConnectAuthCode(request_validator)
openid_connect_implicit = OpenIDConnectImplicit(request_validator)
openid_connect_hybrid = OpenIDConnectHybrid(request_validator)

bearer = BearerToken(request_validator, token_generator,
token_expires_in, refresh_token_generator)

jwt = JWTToken(request_validator, token_generator,
token_expires_in, refresh_token_generator)

auth_grant_choice = AuthCodeGrantDispatcher(default_auth_grant=auth_grant, oidc_auth_grant=openid_connect_auth)
implicit_grant_choice = ImplicitTokenGrantDispatcher(default_implicit_grant=implicit_grant, oidc_implicit_grant=openid_connect_implicit)

# See http://openid.net/specs/oauth-v2-multiple-response-types-1_0.html#Combinations for valid combinations
# internally our AuthorizationEndpoint will ensure they can appear in any order for any valid combination
AuthorizationEndpoint.__init__(self, default_response_type='code',
response_types={
'code': auth_grant_choice,
'token': implicit_grant_choice,
'id_token': openid_connect_implicit,
'id_token token': openid_connect_implicit,
'code token': openid_connect_hybrid,
'code id_token': openid_connect_hybrid,
'code id_token token': openid_connect_hybrid,
'code': auth_grant,
'token': implicit_grant,
'none': auth_grant
},
default_token_type=bearer)

token_grant_choice = AuthTokenGrantDispatcher(request_validator, default_token_grant=auth_grant, oidc_token_grant=openid_connect_auth)

TokenEndpoint.__init__(self, default_grant_type='authorization_code',
grant_types={
'authorization_code': token_grant_choice,
'authorization_code': auth_grant,
'password': password_grant,
'client_credentials': credentials_grant,
'refresh_token': refresh_grant,
},
default_token_type=bearer)
ResourceEndpoint.__init__(self, default_token='Bearer',
token_types={'Bearer': bearer, 'JWT': jwt})
token_types={'Bearer': bearer})
RevocationEndpoint.__init__(self, request_validator)
IntrospectEndpoint.__init__(self, request_validator)

Expand Down
123 changes: 23 additions & 100 deletions oauthlib/oauth2/rfc6749/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,106 +274,6 @@ class UnsupportedTokenTypeError(OAuth2Error):
error = 'unsupported_token_type'


class FatalOpenIDClientError(FatalClientError):
pass


class OpenIDClientError(OAuth2Error):
pass


class InteractionRequired(OpenIDClientError):
"""
The Authorization Server requires End-User interaction to proceed.

This error MAY be returned when the prompt parameter value in the
Authentication Request is none, but the Authentication Request cannot be
completed without displaying a user interface for End-User interaction.
"""
error = 'interaction_required'
status_code = 401


class LoginRequired(OpenIDClientError):
"""
The Authorization Server requires End-User authentication.

This error MAY be returned when the prompt parameter value in the
Authentication Request is none, but the Authentication Request cannot be
completed without displaying a user interface for End-User authentication.
"""
error = 'login_required'
status_code = 401


class AccountSelectionRequired(OpenIDClientError):
"""
The End-User is REQUIRED to select a session at the Authorization Server.

The End-User MAY be authenticated at the Authorization Server with
different associated accounts, but the End-User did not select a session.
This error MAY be returned when the prompt parameter value in the
Authentication Request is none, but the Authentication Request cannot be
completed without displaying a user interface to prompt for a session to
use.
"""
error = 'account_selection_required'


class ConsentRequired(OpenIDClientError):
"""
The Authorization Server requires End-User consent.

This error MAY be returned when the prompt parameter value in the
Authentication Request is none, but the Authentication Request cannot be
completed without displaying a user interface for End-User consent.
"""
error = 'consent_required'
status_code = 401


class InvalidRequestURI(OpenIDClientError):
"""
The request_uri in the Authorization Request returns an error or
contains invalid data.
"""
error = 'invalid_request_uri'
description = 'The request_uri in the Authorization Request returns an ' \
'error or contains invalid data.'


class InvalidRequestObject(OpenIDClientError):
"""
The request parameter contains an invalid Request Object.
"""
error = 'invalid_request_object'
description = 'The request parameter contains an invalid Request Object.'


class RequestNotSupported(OpenIDClientError):
"""
The OP does not support use of the request parameter.
"""
error = 'request_not_supported'
description = 'The request parameter is not supported.'


class RequestURINotSupported(OpenIDClientError):
"""
The OP does not support use of the request_uri parameter.
"""
error = 'request_uri_not_supported'
description = 'The request_uri parameter is not supported.'


class RegistrationNotSupported(OpenIDClientError):
"""
The OP does not support use of the registration parameter.
"""
error = 'registration_not_supported'
description = 'The registration parameter is not supported.'


class InvalidTokenError(OAuth2Error):
"""
The access token provided is expired, revoked, malformed, or
Expand Down Expand Up @@ -402,6 +302,29 @@ class InsufficientScopeError(OAuth2Error):
"the access token.")


class ConsentRequired(OAuth2Error):
"""
The Authorization Server requires End-User consent.

This error MAY be returned when the prompt parameter value in the
Authentication Request is none, but the Authentication Request cannot be
completed without displaying a user interface for End-User consent.
"""
error = 'consent_required'
status_code = 401

class LoginRequired(OAuth2Error):
"""
The Authorization Server requires End-User authentication.

This error MAY be returned when the prompt parameter value in the
Authentication Request is none, but the Authentication Request cannot be
completed without displaying a user interface for End-User authentication.
"""
error = 'login_required'
status_code = 401


def raise_from_error(error, params=None):
import inspect
import sys
Expand Down
8 changes: 0 additions & 8 deletions oauthlib/oauth2/rfc6749/grant_types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,3 @@
from .resource_owner_password_credentials import ResourceOwnerPasswordCredentialsGrant
from .client_credentials import ClientCredentialsGrant
from .refresh_token import RefreshTokenGrant
from .openid_connect import OpenIDConnectBase
from .openid_connect import OpenIDConnectAuthCode
from .openid_connect import OpenIDConnectImplicit
from .openid_connect import OpenIDConnectHybrid
from .openid_connect import OIDCNoPrompt
from .openid_connect import AuthCodeGrantDispatcher
from .openid_connect import AuthTokenGrantDispatcher
from .openid_connect import ImplicitTokenGrantDispatcher
4 changes: 2 additions & 2 deletions oauthlib/oauth2/rfc6749/request_validator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""
oauthlib.oauth2.rfc6749.grant_types
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
oauthlib.oauth2.rfc6749.request_validator
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""
from __future__ import absolute_import, unicode_literals

Expand Down
40 changes: 0 additions & 40 deletions oauthlib/oauth2/rfc6749/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,43 +315,3 @@ def estimate_type(self, request):
return 5
else:
return 0


class JWTToken(TokenBase):
__slots__ = (
'request_validator', 'token_generator',
'refresh_token_generator', 'expires_in'
)

def __init__(self, request_validator=None, token_generator=None,
expires_in=None, refresh_token_generator=None):
self.request_validator = request_validator
self.token_generator = token_generator or random_token_generator
self.refresh_token_generator = (
refresh_token_generator or self.token_generator
)
self.expires_in = expires_in or 3600

def create_token(self, request, refresh_token=False, save_token=False):
"""Create a JWT Token, using requestvalidator method."""

if callable(self.expires_in):
expires_in = self.expires_in(request)
else:
expires_in = self.expires_in

request.expires_in = expires_in

return self.request_validator.get_jwt_bearer_token(None, None, request)

def validate_request(self, request):
token = get_token_from_header(request)
return self.request_validator.validate_jwt_bearer_token(
token, request.scopes, request)

def estimate_type(self, request):
split_header = request.headers.get('Authorization', '').split()

if len(split_header) == 2 and split_header[0] == 'Bearer' and split_header[1].startswith('ey') and split_header[1].count('.') in (2, 4):
return 10
return 0
Empty file added oauthlib/openid/__init__.py
Empty file.
Empty file.
Empty file.
Loading