R1D5 CloudWatch and Auth0 Rabbit Hole

I wrapped up my work on OldPosts by creating a CloudWatch event to trigger my Lambda job every day. This will automatically add old posts to buffer if any exist. CloudWatch is useful for many things, but in this particular case it is being used as Cron As A Service.

Next I fell down a huge rabbit hole trying to get started with Auth0 in a Flask application. The documentation is okay, but I have bought into using the factory pattern in Flask, and it got a little messy.

Working with the factory pattern can be kind of a mind f**k because it seems like if you put the config in once place you pay for it in another. I ended up going with this approach.

  1. Add the oauth remote app to the factory
         with app.app_context():
             auth0 = oauth.remote_app(
                 'auth0',
                 consumer_key=app.config['AUTH0_CLIENT_ID'],
                 consumer_secret=app.config['AUTH0_CLIENT_SECRET'],
                 request_token_params={
                     'scope': 'openid profile',
                     'audience': 'https://{0}/userinfo'.format(app.config['AUTH0_DOMAIN'])
                 },
                 base_url='https://{0}'.format(app.config['AUTH0_DOMAIN']),
                 access_token_method='POST',
                 access_token_url='oauth/token',
                 authorize_url='/authorize',
             )
    
  2. In a separate module, when calling auth0 I grab the object instead of the variable.
     resp = oauth.remote_apps['auth0'].authorized_response()
    

It’s still not clear to me how to make auth0 “global” using the factory pattern but this approach does work.

Overall once I got auth0 to work I was super impressed with the product. Every time I start a new project I spend a week re-inveting the wheel with auth and forget what the project was even about. This time I only spent an evening implementing Auth0 and now I can move on to the actual meat of the code.

One thought on “R1D5 CloudWatch and Auth0 Rabbit Hole”

Leave a Reply

%d bloggers like this: