def confirm_authorization_request(self): """When consumer confirm the authorization.""" server = self.server scope = request.params.get('scope') or '' scopes = scope.split() credentials = dict( client_id=request.params.get('client_id'), redirect_uri=request.params.get('redirect_uri', None), response_type=request.params.get('response_type', None), state=request.params.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(True) 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) return redirect(e.in_uri(self.error_uri)) except oauth2.OAuth2Error as e: log.debug('OAuth2Error: %r', e) return redirect(e.in_uri(redirect_uri or self.error_uri))
def confirm_authorization_request(self): """When consumer confirm the authorization.""" server = self.server scope = request.params.get('scope') or '' scopes = scope.split() credentials = dict( client_id=request.params.get('client_id'), redirect_uri=request.params.get('redirect_uri', None), response_type=request.params.get('response_type', None), state=request.params.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(True) 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) return redirect(e.in_uri(self.error_uri)) except oauth2.OAuth2Error as e: log.debug('OAuth2Error: %r', e) return redirect(e.in_uri(redirect_uri or self.error_uri))
def decorated(*args, **kwargs): server = self.server uri, http_method, body, headers = extract_params(True) credentials = f(*args, **kwargs) or {} log.debug('Fetched extra credentials, %r.', credentials) ret = server.create_token_response(uri, http_method, body, headers, credentials) return create_response(*ret)
def decorated(*args, **kwargs): server = self.server uri, http_method, body, headers = extract_params(True) credentials = f(*args, **kwargs) or {} log.debug('Fetched extra credentials, %r.', credentials) ret = server.create_token_response( uri, http_method, body, headers, credentials ) return create_response(*ret)
def decorated(*args, **kwargs): server = self.server token = request.params.get('token') request.token_type_hint = request.params.get('token_type_hint') if token: request.token = token uri, http_method, body, headers = extract_params(True) ret = server.create_revocation_response( uri, headers=headers, body=body, http_method=http_method) return create_response(*ret)
def verify_request(self, scopes): """Verify current request, get the oauth data. If you can't use the ``check_oauth`` decorator, you can fetch the data in your request body:: def your_handler(): valid, req = oauth.verify_request(['email']) if valid: return jsonify(user=req.user) return jsonify(status='error') """ uri, http_method, body, headers = extract_params(False) return self.server.verify_request(uri, http_method, body, headers, scopes)
def verify_request(self, scopes): """Verify current request, get the oauth data. If you can't use the ``check_oauth`` decorator, you can fetch the data in your request body:: def your_handler(): valid, req = oauth.verify_request(['email']) if valid: return jsonify(user=req.user) return jsonify(status='error') """ uri, http_method, body, headers = extract_params(False) return self.server.verify_request( uri, http_method, body, headers, scopes )
def decorated(*args, **kwargs): # raise if server not implemented server = self.server uri, http_method, body, headers = extract_params(True) if request.method in ('GET', 'HEAD'): redirect_uri = request.query.get('redirect_uri', self.error_uri) log.debug('Found redirect_uri %s.', redirect_uri) try: ret = server.validate_authorization_request( uri, http_method, body, headers ) scopes, credentials = ret kwargs['scopes'] = scopes kwargs.update(credentials) except oauth2.FatalClientError as e: log.debug('Fatal client error %r', e) return redirect(e.in_uri(self.error_uri)) except oauth2.OAuth2Error as e: log.debug('OAuth2Error: %r', e) return redirect(e.in_uri(redirect_uri)) else: redirect_uri = request.params.get( 'redirect_uri', self.error_uri ) try: rv = f(*args, **kwargs) except oauth2.FatalClientError as e: log.debug('Fatal client error %r', e) return redirect(e.in_uri(self.error_uri)) except oauth2.OAuth2Error as e: log.debug('OAuth2Error: %r', e) return redirect(e.in_uri(redirect_uri)) if not isinstance(rv, bool): # if is a response or redirect return rv if not rv: # denied by user e = oauth2.AccessDeniedError() return redirect(e.in_uri(redirect_uri)) return self.confirm_authorization_request()