Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update action_api.md #557

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions docs/action_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,34 @@ The token is provided as a standard HTTP `Authorization` header with a `token` l
Authorization: Token token="abcdefg123456789"
```

Here's an example (in python) of checking for this header. Note this function should be called before executing anything else in all three main workflows (execute, list, form). The entry point is the main() function.
```
def authenticate(request):
if request.method != 'POST':
r = '|ERROR| Request must be POST'; print (r)
return Response(r, status=401, mimetype='application/json')

elif 'X-Forwarded-Authorization' not in request.headers:
r = '|ERROR| Request does not have auth token'; print (r)
return Response(r, status=400, mimetype='application/json')

else:
expected_auth_header = 'Token token="{}"'.format(os.environ.get('LOOKER_AUTH_SECRET'))
submitted_auth = request.headers['X-Forwarded-Authorization']
if hmac.compare_digest(expected_auth_header,submitted_auth):
return Response(status=200, mimetype='application/json')

else:
r = '|ERROR| Incorrect token'; print (r)
return Response(r, status=403, mimetype='application/json')



def main(request):
auth = authenticate(request)
if auth.status_code != 200:
return auth
# Continue with the intended functionality, it will only get executed if auth.status_code is 200
```

Each individual action can also specify additional options or credentials as part of its `params`. This is useful if you need different secrets or global configurations for each action.
Loading