Example #1
0
    def get(self):
        client_id = self.get_argument('client_id', '')
        client_secret = self.get_argument('client_secret', '')
        redirect_uri = self.get_argument('redirect_uri', '')
        grant_type = self.get_argument('grant_type', '')
        code = self.get_argument('code', '')
        user_id = self.current_user_id

        if grant_type == 'authorization_code':
            if oauth_authorization_code_verify(code):
                authorization_id = oauth_authorization_code_verify(code)
                if oauth_secret_verify(client_id, client_secret):
                    if oauth_client_uri.get(client_id) == redirect_uri:
                        id, access_token = oauth_access_token_new(client_id, user_id)
                        refresh_token = oauth_refresh_token_new(client_id, id)
                        oauth_authorize_code_rm(authorization_id)

                        data = {
                            'access_token':access_token,
                            'refresh_token':refresh_token,
                            'expires_in': 87063,
                            'scope': 'basic',
                            'user_id':user_id
                        }
                        self.finish(data)
                    else:
                        self.finish({'error':'redirect uri not same as the redirect uri of this app'})
                else:
                    self.finish({'error':'oauth secret verify error'})
            else:
                self.finish({'error':'oauth authorization code verify error'})
        else:
            self.finish({'error':'grant type error'})
Example #2
0
 def get(self, oauth_client_id):
     client = OauthClient.get(oauth_client_id)
     if client and client.can_admin(self.current_user_id):
         self.render(
             cid=client.cid,
             name=client.name,
             site=client.site,
             uri=oauth_client_uri.get(oauth_client_id),
             txt=txt_get(oauth_client_id),
             oauth_client_id=oauth_client_id,
         )
     else:
         return self.redirect('/')
Example #3
0
 def get(self, oauth_client_id):
     client = OauthClient.get(oauth_client_id)
     if client and client.can_admin(self.current_user_id):
         self.render(
             cid=client.cid,
             name=client.name,
             site=client.site,
             uri=oauth_client_uri.get(oauth_client_id),
             txt=txt_get(oauth_client_id),
             oauth_client_id=oauth_client_id,
         )
     else:
         return self.redirect('/')
Example #4
0
 def get(self):
     client_id = self.get_argument('client_id', '')
     response_type = self.get_argument('response_type', '')
     redirect_uri = self.get_argument('redirect_uri', '')
     if response_type == 'code':
         if client_id:
             if oauth_client_uri.get(client_id) == redirect_uri:
                 self.render(client_id=client_id)
             else:
                 self.finish({'error':'redirect_uri error!'})
         else:
             self.finish({'error':'no client_id!'})
     else:
         self.finish({'error':'response_type error!'})
Example #5
0
 def get(self):
     client_id = self.get_argument('client_id', '')
     response_type = self.get_argument('response_type', '')
     redirect_uri = self.get_argument('redirect_uri', '')
     if response_type == 'code':
         if client_id:
             if oauth_client_uri.get(client_id) == redirect_uri:
                 self.render(client_id=client_id)
             else:
                 self.finish({'error': 'redirect_uri error!'})
         else:
             self.finish({'error': 'no client_id!'})
     else:
         self.finish({'error': 'response_type error!'})
Example #6
0
    def get(self):
        client_id = self.get_argument('client_id', '')
        client_secret = self.get_argument('client_secret', '')
        redirect_uri = self.get_argument('redirect_uri', '')
        grant_type = self.get_argument('grant_type', '')
        code = self.get_argument('code', '')
        user_id = self.current_user_id

        if grant_type == 'authorization_code':
            if oauth_authorization_code_verify(code):
                authorization_id = oauth_authorization_code_verify(code)
                if oauth_secret_verify(client_id, client_secret):
                    if oauth_client_uri.get(client_id) == redirect_uri:
                        id, access_token = oauth_access_token_new(
                            client_id, user_id)
                        refresh_token = oauth_refresh_token_new(client_id, id)
                        oauth_authorize_code_rm(authorization_id)

                        data = {
                            'access_token': access_token,
                            'refresh_token': refresh_token,
                            'expires_in': 87063,
                            'scope': 'basic',
                            'user_id': user_id
                        }
                        self.finish(data)
                    else:
                        self.finish({
                            'error':
                            'redirect uri not same as the redirect uri of this app'
                        })
                else:
                    self.finish({'error': 'oauth secret verify error'})
            else:
                self.finish({'error': 'oauth authorization code verify error'})
        else:
            self.finish({'error': 'grant type error'})