Oauthlib: 范围在代码 response_type 中是可选的吗?

创建于 2016-02-23  ·  3评论  ·  资料来源: oauthlib/oauthlib

你好!

当我阅读_oauthlib/oauth2/rfc6749/grant_types/authorization_code.py _ 中的文档时,我可以看到:
scope OPTIONAL. The scope of the access request as described by 第 3.3 节_.

但是这个检查假设范围是强制性的
if not request.scopes: raise ValueError('Scopes must be set on post auth.')

我误解了什么吗?

Bug OAuth2-Provider

最有用的评论

我遇到了同样的行为,我也不明白。 RFC 表示范围是可选的,不应引发异常。

所有3条评论

我遇到了同样的行为,我也不明白。 RFC 表示范围是可选的,不应引发异常。

这也咬了我一口。 我猴子修补了它。

# A bit of monkey patching here. OAuthlib states that scope are optional, also
# RFC6749 confirms this, however, one method of the AuthorizationCodeGrant
# class requires scopes to be defined. As I don't know if we are going to use
# scopes, or what the scopes might be, I am going to monkey-patch this class to
# make scopes optional.
#
# https://github.com/idan/oauthlib/issues/406

# Some imports we need for the patching of the monkey...
from oauthlib.oauth2.rfc6749 import errors


def create_authorization_response(self, request, token_handler):
    """
    Monkey-patched version of this method that allows undefined scopes.
    """
    try:
        # Right here is where the base method checks scopes. We omit this check
        # but the rest of the method body is identical.

        self.validate_authorization_request(request)

        log.debug('Pre resource owner authorization validation ok for %r.',
                  request)
    except errors.FataClientError as e:
        log.debug('Fatal client error during validation of %r. %r.',
                  request, e)
        raise
    except errors.OAuth2Error as e:
        log.debug('Client error during validation of %r. %r.', request, e)
        request.redirect_uri = request.redirect_uri or self.error_uri
        return {
            'Location': common.add_params_to_uri(request.redirect_uri,
                                                 e.twotuples)
        }, None, 302

    grant = self.create_authorization_code(request)
    for modifier in self._code_modifiers:
        grant = modifier(grant, token_handler, request)
    log.debug('Saving grant %r for %r.', grant, request)
    self.request_validator.save_authorization_code(
        request.client_id, grant, request)
    return self.prepare_authorization_response(
        request, grant, {}, None, 302)


from oauthlib.oauth2.rfc6749.grant_types.authorization_code import (
    AuthorizationCodeGrant, log
)

AuthorizationCodeGrant.create_authorization_response = \
    create_authorization_response

# Now we can import the rest of what we need from oauthlib.

你是对的,已经在https://github.com/oauthlib/oauthlib/pull/475 上提出了与 Implicit 相关的 PR,我们应该将它扩展到 AuthCode!

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

ggiill picture ggiill  ·  7评论

polamayster picture polamayster  ·  19评论

ib-lundgren picture ib-lundgren  ·  21评论

JonathanHuot picture JonathanHuot  ·  10评论

thedrow picture thedrow  ·  31评论