Mining CLIO

Connecting to Clio

Latest Update: 08.28.2021

clio.com is a popular SAAS offering for managing legal practices. It is a complete system that helps manage day-to-day workflows and operations, including contacts, calendars, documents, billing and more.

Step 1 - Understand Oauth2
There are a number of steps a script has to take when connecting to and API with Oauth2 security. First you create an application and generate an application key, an application secret, and often define a 'callback uri' which will be important in a moment.
Step 2 - Python Authentication
In the case of our current application, we'll be using Python to connect to the api to retrieve some data. So we will be running with the Authlib: Python Authentication library.
The Redirect Workaround
An annoyance of writing a client application using oauth2 is that the token required to connect is often passed back in a redirect uri. We'll get around that with a simple socketserver.TCPServer running on port 8000 that we'll provide to the application as the callback. We'll then access the request path to parse out the token string and then shut down the server.

import http.server
import socketserver

PORT = 8000

response_path = None

class GetHandler(http.server.SimpleHTTPRequestHandler):

    def do_GET(self):

        if '?code' in self.path:
            global response_path
            response_path = self.path
            print('Path Received: ', response_path)

            http.server.SimpleHTTPRequestHandler.do_GET(self)

            print('shutting down server')
            self.server._BaseServer__shutdown_request = True
            self.server.server_close()

# Start: Blocking HTTP server
Handler = GetHandler
with socketserver.TCPServer(("", PORT), Handler) as myhttp:
    print('Serving port:', PORT)
    myhttp.serve_forever()
# End: Blocking HTTP Server

print(f"Path with code: {response_path}")
Parting Thoughts

Oauth has some great capabilities, but sometimes working with it can be difficult and workarounds are necessary.