本文整理汇总了Python中oauthlib.oauth2.OAuth2Error方法的典型用法代码示例。如果您正苦于以下问题:Python oauth2.OAuth2Error方法的具体用法?Python oauth2.OAuth2Error怎么用?Python oauth2.OAuth2Error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oauthlib.oauth2
的用法示例。
在下文中一共展示了oauth2.OAuth2Error方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: complete_zoom_user_in_realm
# 需要导入模块: from oauthlib import oauth2 [as 别名]
# 或者: from oauthlib.oauth2 import OAuth2Error [as 别名]
def complete_zoom_user_in_realm(
request: HttpRequest,
code: str = REQ(),
state: Dict[str, str] = REQ(validator=check_dict([("sid", check_string)], value_validator=check_string)),
) -> HttpResponse:
if not constant_time_compare(state["sid"], get_zoom_sid(request)):
raise JsonableError(_("Invalid Zoom session identifier"))
oauth = get_zoom_session(request.user)
try:
token = oauth.fetch_token(
"https://zoom.us/oauth/token",
code=code,
client_secret=settings.VIDEO_ZOOM_CLIENT_SECRET,
)
except OAuth2Error:
raise JsonableError(_("Invalid Zoom credentials"))
do_set_zoom_token(request.user, token)
return render(request, "zerver/close_window.html")
示例2: make_zoom_video_call
# 需要导入模块: from oauthlib import oauth2 [as 别名]
# 或者: from oauthlib.oauth2 import OAuth2Error [as 别名]
def make_zoom_video_call(request: HttpRequest, user: UserProfile) -> HttpResponse:
oauth = get_zoom_session(user)
if not oauth.authorized:
raise InvalidZoomTokenError
try:
res = oauth.post("https://api.zoom.us/v2/users/me/meetings", json={})
except OAuth2Error:
do_set_zoom_token(user, None)
raise InvalidZoomTokenError
if res.status_code == 401:
do_set_zoom_token(user, None)
raise InvalidZoomTokenError
elif not res.ok:
raise JsonableError(_("Failed to create Zoom call"))
return json_success({"url": res.json()["join_url"]})
示例3: _get_user_data
# 需要导入模块: from oauthlib import oauth2 [as 别名]
# 或者: from oauthlib.oauth2 import OAuth2Error [as 别名]
def _get_user_data(self):
if not hasattr(request, '_user_data'):
try:
resp = self.session.get(self.domain + '/oauth/verify').json()
current_app.logger.debug(u"SSO lookup results: {}".format(resp))
except OAuth2Error as e:
current_app.logger.error(u"Error verifying user data for user "
u"'{}': {}".format(current_user, e))
# The session can be bugged in some situations. Kill it to be
# sure.
del self.session
raise
try:
char_data = {
'name': resp[u'CharacterName'],
'id': resp[u'CharacterID'],
'owner_hash': resp[u'CharacterOwnerHash'],
}
request._user_data = char_data
except (TypeError, KeyError):
abort(500, u"Error in receiving EVE SSO response: {}".format(
resp))
return request._user_data
示例4: create_metadata_response
# 需要导入模块: from oauthlib import oauth2 [as 别名]
# 或者: from oauthlib.oauth2 import OAuth2Error [as 别名]
def create_metadata_response(self):
def decorator(f):
@functools.wraps(f)
def wrapper():
assert self._oauthlib, "BottleOAuth2 not initialized with OAuthLib"
uri, http_method, body, headers = extract_params(bottle.request)
try:
resp_headers, resp_body, resp_status = self._oauthlib.create_metadata_response(
uri, http_method, body, headers
)
except OAuth2Error as e:
resp_headers, resp_body, resp_status = e.headers, e.json, e.status_code
set_response(bottle.request, bottle.response, resp_status,
resp_headers, resp_body, force_json=True)
func_response = f()
if func_response:
return func_response
return bottle.response
return wrapper
return decorator
示例5: create_introspect_response
# 需要导入模块: from oauthlib import oauth2 [as 别名]
# 或者: from oauthlib.oauth2 import OAuth2Error [as 别名]
def create_introspect_response(self):
def decorator(f):
@functools.wraps(f)
def wrapper(*args, **kwargs):
assert self._oauthlib, "BottleOAuth2 not initialized with OAuthLib"
uri, http_method, body, headers = extract_params(bottle.request)
try:
resp_headers, resp_body, resp_status = self._oauthlib.create_introspect_response(
uri, http_method, body, headers
)
except OAuth2Error as e:
resp_headers, resp_body, resp_status = e.headers, e.json, e.status_code
set_response(bottle.request, bottle.response, resp_status, resp_headers,
resp_body, force_json=True)
func_response = f(*args, **kwargs)
if func_response:
return func_response
return bottle.response
return wrapper
return decorator
示例6: create_revocation_response
# 需要导入模块: from oauthlib import oauth2 [as 别名]
# 或者: from oauthlib.oauth2 import OAuth2Error [as 别名]
def create_revocation_response(self):
def decorator(f):
@functools.wraps(f)
def wrapper(*args, **kwargs):
assert self._oauthlib, "BottleOAuth2 not initialized with OAuthLib"
uri, http_method, body, headers = extract_params(bottle.request)
try:
resp_headers, resp_body, resp_status = self._oauthlib.create_revocation_response(
uri, http_method=http_method, body=body, headers=headers
)
except OAuth2Error as e:
resp_headers, resp_body, resp_status = e.headers, e.json, e.status_code
set_response(bottle.request, bottle.response, resp_status, resp_headers, resp_body)
func_response = f(*args, **kwargs)
if func_response:
return func_response
return bottle.response
return wrapper
return decorator
示例7: refresh
# 需要导入模块: from oauthlib import oauth2 [as 别名]
# 或者: from oauthlib.oauth2 import OAuth2Error [as 别名]
def refresh(self, user):
"""Refreshes the current user's information.
Attempts to refresh the pilots and groups for the given user. If the
current access token has expired, the refresh token is used to get a
new access token.
"""
try:
self._update_user_info()
except OAuth2Error:
return False
else:
return True
示例8: create_token_response
# 需要导入模块: from oauthlib import oauth2 [as 别名]
# 或者: from oauthlib.oauth2 import OAuth2Error [as 别名]
def create_token_response(self, credentials=None):
def decorator(f):
@functools.wraps(f)
def wrapper(*args, **kwargs):
assert self._oauthlib, "BottleOAuth2 not initialized with OAuthLib"
# Get any additional creds
try:
credentials_extra = credentials(bottle.request)
except TypeError:
credentials_extra = credentials
uri, http_method, body, headers = extract_params(bottle.request)
try:
resp_headers, resp_body, resp_status = self._oauthlib.create_token_response(
uri, http_method, body, headers, credentials_extra
)
except OAuth2Error as e:
resp_headers, resp_body, resp_status = e.headers, e.json, e.status_code
set_response(bottle.request, bottle.response, resp_status,
resp_headers, resp_body)
func_response = f(*args, **kwargs)
if func_response:
return func_response
return bottle.response
return wrapper
return decorator
示例9: create_authorization_response
# 需要导入模块: from oauthlib import oauth2 [as 别名]
# 或者: from oauthlib.oauth2 import OAuth2Error [as 别名]
def create_authorization_response(self):
def decorator(f):
@functools.wraps(f)
def wrapper(*args, **kwargs):
assert self._oauthlib, "BottleOAuth2 not initialized with OAuthLib"
uri, http_method, body, headers = extract_params(bottle.request)
scope = bottle.request.params.get('scope', '').split(' ')
try:
resp_headers, resp_body, resp_status = self._oauthlib.create_authorization_response(
uri, http_method=http_method, body=body, headers=headers, scopes=scope
)
except FatalClientError as e:
if self._error_uri:
raise bottle.HTTPResponse(status=302, headers={"Location": add_params_to_uri(
self._error_uri, {'error': e.error, 'error_description': e.description}
)})
raise e
except OAuth2Error as e:
resp_headers, resp_body, resp_status = e.headers, e.json, e.status_code
set_response(bottle.request, bottle.response, resp_status, resp_headers, resp_body)
func_response = f(*args, **kwargs)
if func_response:
return func_response
return bottle.response
return wrapper
return decorator
示例10: confirm_authorization_request
# 需要导入模块: from oauthlib import oauth2 [as 别名]
# 或者: from oauthlib.oauth2 import OAuth2Error [as 别名]
def confirm_authorization_request(self):
"""When consumer confirm the authorization."""
server = self.server
scope = request.values.get('scope') or ''
scopes = scope.split()
credentials = dict(
client_id=request.values.get('client_id'),
redirect_uri=request.values.get('redirect_uri', None),
response_type=request.values.get('response_type', None),
state=request.values.get('state', None))
log.debug('Fetched credentials from request %r.', credentials)
redirect_uri = credentials.get('redirect_uri')
log.debug('Found redirect_uri %s.', redirect_uri)
uri, http_method, body, headers = extract_params()
try:
ret = server.create_authorization_response(
uri, http_method, body, headers, scopes, credentials)
log.debug('Authorization successful.')
return create_response(*ret)
except oauth2.FatalClientError as e:
log.debug('Fatal client error %r', e, exc_info=True)
return redirect(e.in_uri(self.error_uri))
except oauth2.OAuth2Error as e:
log.debug('OAuth2Error: %r', e, exc_info=True)
return redirect(e.in_uri(redirect_uri or self.error_uri))
except Exception as e:
log.exception(e)
return redirect(
add_params_to_uri(self.error_uri, {'error': str(e)}))
示例11: oauth2callback
# 需要导入模块: from oauthlib import oauth2 [as 别名]
# 或者: from oauthlib.oauth2 import OAuth2Error [as 别名]
def oauth2callback():
if '_oauth_state' not in session:
return redirect(url_for('users.login'))
try:
user = current_app.oauth_provider.fetch_user()
except OAuth2Error:
current_app.logger.exception("Failed to authenticate with oauth")
return redirect(url_for('users.logout'))
login_user(user)
flash(u'Welcome {0}.'.format(user.first_name or user.username), 'info')
current_app.logger.info("%s logged in", user.username)
return redirect(url_for('users.login'))
示例12: __init__
# 需要导入模块: from oauthlib import oauth2 [as 别名]
# 或者: from oauthlib.oauth2 import OAuth2Error [as 别名]
def __init__(self, client_id, client_secret, redirect_uri, token=None, code=None, scope=None):
"""
:param client_id [string]: Client id obtained during registration.
:param client_secret [string]: Client secret obtained during registration.
:param redirect_uri [string]: Redirect URI you registered as callback.
:param token [dict]: Token dictionary, must include access_token and token_type.
:param code [string]: Authorization code to get access token.
:param scope [list]: List of scopes you wish to request access to.
:raise UnsplashAuthError: OAuth2Session has OAuth2Error.
"""
self.access_token_url = "%s/oauth/token" % self.BASE_AUTH_URL
self.authorization_url = "%s/oauth/authorize" % self.BASE_AUTH_URL
self.client_id = client_id
self.client_secret = client_secret
self.redirect_uri = redirect_uri
self.token = None
self.access_token = None
self.is_authenticated = False
self.scope_list = [
"public",
"read_user",
"write_user",
"read_photos",
"write_photos",
"write_likes",
"write_followers",
"read_collections",
"write_collections"
]
self.scope = scope or self.scope_list
try:
if token:
self.oauth = OAuth2Session(
client_id=self.client_id, redirect_uri=self.redirect_uri, scope=self.scope, token=token
)
self.access_token = self.oauth.access_token
self.token = token
self.is_authenticated = True
elif code:
self.oauth = OAuth2Session(client_id=self.client_id, redirect_uri=self.redirect_uri, scope=self.scope)
self.access_token = self.get_access_token(code)
self.is_authenticated = True
except OAuth2Error as e:
raise UnsplashAuthError(e)
示例13: view
# 需要导入模块: from oauthlib import oauth2 [as 别名]
# 或者: from oauthlib.oauth2 import OAuth2Error [as 别名]
def view(self):
"""Handle creating and/or logging in the user and updating their
:py:class:`~.Pilot`\s and :py:class:`~.Group`\s.
"""
oauth = OAuth2Session(self.client_id,
redirect_uri=self.redirect_uri,
state=session['state'])
try:
token = oauth.fetch_token(self.token_url,
authorization_response=request.url,
method=self.oauth_method,
client_secret=self.client_secret,
auth=(self.client_id, self.client_secret))
except OAuth2Error as e:
# TRANS: When there's an error associated with a login.
flash(gettext(u"Login failed: %(error)s", error=e.error))
if 'SENTRY_RELEASE' in current_app.config:
sentry.captureException()
return redirect(url_for('login.login'))
# Set the current session manually because the automated method relies
# on current_user.
self.session = OAuth2Session(self.client_id, token=token)
# Get the User object for this user, creating one if needed
user = self.get_user()
# Update the tokens (and related info) for the user
user.access_token = token[u'access_token']
# If not given by the server, use the default expiry time
if u'expires_in' in token:
user.set_expiration(token[u'expires_in'])
else:
user.set_expiration(self.default_token_expiry)
user.refresh_token = token.get(u'refresh_token')
db.session.commit()
if user is not None:
# Login the user, so current_user will work
self.login_user(user)
else:
# TRANS: Error shown for a failed login.
flash(gettext(u"Login failed."), u'error')
return redirect(url_for('login.login'))
# Update admins, groups and pilots for the current user
self._update_user_info()
# Redirect to the 'next' parameter given to the 'login' view.
# The next parameter is automatically added by Flask-Login.
# Check that the 'next' parameter is safe.
next_url = request.args.get('next')
if next_url is not None:
if not is_safe_redirect(next_url):
next_url = None
return redirect(next_url or url_for('index'))