示例#1
0
    def get_oauth_session(self):
        known_state = session.get(AUTH_STATE_KEY)
        redirect_url = urljoin(request.url_root, self.redirect_path)

        if self.grant_type and self.grant_type == CLIENT_CREDENTIALS_GRANT_TYPE:
            client = BackendApplicationClient(client_id=self.client_id)
            oauth_session = OAuth2Session(client=client,
                                          token=session.get(AUTH_TOKEN_KEY))

        elif self.grant_type and self.grant_type == IMPLICIT_GRANT_TYPE:
            client = MobileApplicationClient(self.client_id)
            client.response_type = self.config.get(RESPONSE_TYPE_CONFIG)
            oauth_session = OAuth2Session(
                client_id=self.client_id,
                state=known_state,
                scope=self.config.get(SCOPE_CONFIG).split(),
                redirect_uri=redirect_url,
                client=client,
                token=session.get(AUTH_TOKEN_KEY))
        else:
            client = WebApplicationClient(self.client_id)
            oauth_session = OAuth2Session(
                client_id=self.client_id,
                state=known_state,
                scope=self.config.get(SCOPE_CONFIG).split(),
                redirect_uri=redirect_url,
                client=client,
                token=session.get(AUTH_TOKEN_KEY))

        return oauth_session