# Path: huacaya/auth/auth.py
# class Provider(object):
# class Server(object):
# class ServerDaoWithStorage(object):
#     def __init__(self, server):
#     def authorization_request(self, account_ident, client_id, redirect_uri=None, scope=None):
#     def verify_authorization_code(self, authorization_code):
#     def authorization_code_grant(self, authorization_code, client_id, redirect_uri=None):
#     def verify_token(self, token):
#     def verify_scope(self, access_token, scope):
#     def refresh_token_grant(self, refresh_token):
#     def implicit_grant(self, account_ident, client_id, redirect_uri=None, scope=None):
#     def password_grant(self, account_ident, credentials, scope=None):
#     def __init__(self, dao=None):
#     def register_client(self, client_id, **kwds):
#     def register_account(self, account):
#     def authorization_request(self, account_ident, client_id, redirect_uri=None, scope=None):
#     def authorization_code_grant(self, authorization_code, client_id=None, redirect_uri=None):
#     def verify_authorization_code(self, authorization_code):
#     def verify_token(self, token):
#     def verify_scope(self, access_token, scope):
#     def refresh_token_grant(self, refresh_token):
#     def implicit_grant(self, account_ident, client_id, redirect_uri=None, scope=None):
#     def password_grant(self, account_ident, credentials, scope=None):
#     def revoke_authorization_code(self, authorization_code):
#     def revoke_token(self, token):
#     def _redirect_uri_identical(self, auth_redirect_uri, acc_redirect_url):
#     def has_client_id(self, client_id):
#     def get_accounts(self):
#     def get_tokens(self):
#     def get_clients(self):
#     def find_account(self, credentials):
#     def get_account_by_token(self, token):
#     def __init__(self, storage):
#     def _clients(self):
#     def _tokens(self):
#     def _accounts(self):
#     def _codes(self):
#     def has_client_id(self, client_id):
#     def insert_client(self, client_data):
#     def has_username(self, username):
#     def insert_account(self, account):
#     def has_authorization_code(self, authorization_code):
#     def insert_authorization_code(self, authorization_code):
#     def has_token(self, token):
#     def find_account_by_token(self, token):
#     def find_account(self, data):
#     def get_account_by_id(self, account_id):
#     def update_token(self, token, param):
#     def get_authorization_code(self, authorization_code):
#     def update_authorization_code(self, authorization_code, param):
#     def insert_token(self, token_data):
#     def get_token(self, token):
#     def get_accounts(self):
#     def get_tokens(self):
#     def get_clients(self):


import os
import uuid
import json
import datetime
import tornado.web
import logging
from tornado.web import HTTPError
from tornado.escape import json_decode
    from urllib import urlencode
    from urlparse import urlsplit, urlunsplit
    from urllib.parse import urlencode, urlsplit, urlunsplit
from .auth import AuthorizationError
            authorization_code = self.get_argument('code', None)
            client_id = self.get_argument('client_id', None)
            redirect_uri = self.get_argument('redirect_uri', None)

            try:
                self.write(
                    self._auth_provider.authorization_code_grant(
                        authorization_code, client_id, redirect_uri
                    )
                )
            except BaseException as err:
                self.send_error(400, **err.args[0])
        elif grant_type == 'refresh_token':
            # Refreshing an Access Token
            # https://tools.ietf.org/html/rfc6749#section-6
            try:
                self.write(
                    self._auth_provider.refresh_token_grant(self.get_argument('refresh_token', None))
                )
            except BaseException as err:
                self.send_error(400, **err.args[0])
        elif grant_type == 'password':
            username = self.get_argument('username', None)
            password = self.get_argument('password', None)
            scope = self.get_argument('scope', None)

            try:
                token_data = self._auth_server.password_grant(
                    username, {'username': username, 'password': password}, scope)
                self.write(token_data)

# Path: huacaya/auth/auth.py
# class Provider(object):
# class Server(object):
# class ServerDaoWithStorage(object):
#     def __init__(self, server):
#     def authorization_request(self, account_ident, client_id, redirect_uri=None, scope=None):
#     def verify_authorization_code(self, authorization_code):
#     def authorization_code_grant(self, authorization_code, client_id, redirect_uri=None):
#     def verify_token(self, token):
#     def verify_scope(self, access_token, scope):
#     def refresh_token_grant(self, refresh_token):
#     def implicit_grant(self, account_ident, client_id, redirect_uri=None, scope=None):
#     def password_grant(self, account_ident, credentials, scope=None):
#     def __init__(self, dao=None):
#     def register_client(self, client_id, **kwds):
#     def register_account(self, account):
#     def authorization_request(self, account_ident, client_id, redirect_uri=None, scope=None):
#     def authorization_code_grant(self, authorization_code, client_id=None, redirect_uri=None):
#     def verify_authorization_code(self, authorization_code):
#     def verify_token(self, token):
#     def verify_scope(self, access_token, scope):
#     def refresh_token_grant(self, refresh_token):
#     def implicit_grant(self, account_ident, client_id, redirect_uri=None, scope=None):
#     def password_grant(self, account_ident, credentials, scope=None):
#     def revoke_authorization_code(self, authorization_code):
#     def revoke_token(self, token):
#     def _redirect_uri_identical(self, auth_redirect_uri, acc_redirect_url):
#     def has_client_id(self, client_id):
#     def get_accounts(self):
#     def get_tokens(self):
#     def get_clients(self):
#     def find_account(self, credentials):
#     def get_account_by_token(self, token):
#     def __init__(self, storage):
#     def _clients(self):
#     def _tokens(self):
#     def _accounts(self):
#     def _codes(self):
#     def has_client_id(self, client_id):
#     def insert_client(self, client_data):
#     def has_username(self, username):
#     def insert_account(self, account):
#     def has_authorization_code(self, authorization_code):
#     def insert_authorization_code(self, authorization_code):
#     def has_token(self, token):
#     def find_account_by_token(self, token):
#     def find_account(self, data):
#     def get_account_by_id(self, account_id):
#     def update_token(self, token, param):
#     def get_authorization_code(self, authorization_code):
#     def update_authorization_code(self, authorization_code, param):
#     def insert_token(self, token_data):
#     def get_token(self, token):
#     def get_accounts(self):
#     def get_tokens(self):
#     def get_clients(self):


# Path: huacaya/auth/endpoint.py
import os
import uuid
import json
import datetime
import tornado.web
import logging
from tornado.web import HTTPError
from tornado.escape import json_decode
    from urllib import urlencode
    from urlparse import urlsplit, urlunsplit
    from urllib.parse import urlencode, urlsplit, urlunsplit
from .auth import AuthorizationError

            authorization_code = self.get_argument('code', None)
            client_id = self.get_argument('client_id', None)
            redirect_uri = self.get_argument('redirect_uri', None)

            try:
                self.write(
                    self._auth_provider.authorization_code_grant(
                        authorization_code, client_id, redirect_uri
                    )
                )
            except BaseException as err:
                self.send_error(400, **err.args[0])
        elif grant_type == 'refresh_token':
            # Refreshing an Access Token
            # https://tools.ietf.org/html/rfc6749#section-6
            try:
                self.write(
                    self._auth_provider.refresh_token_grant(self.get_argument('refresh_token', None))
                )
            except BaseException as err:
                self.send_error(400, **err.args[0])
        elif grant_type == 'password':
            username = self.get_argument('username', None)
            password = self.get_argument('password', None)
            scope = self.get_argument('scope', None)

            try:
                token_data = self._auth_server.password_grant(
                    username, {'username': username, 'password': password}, scope)
                self.write(token_data)

            except AuthorizationError: