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

Auth0 Integration V2 #1392

Merged
merged 4 commits into from
Apr 6, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ For general configuration, [click here](docs_website/docs/configurations/general
- Google Cloud OAuth
- Okta OAuth
- GitHub OAuth
- Auth0 OAuth
- LDAP

### Metastore
Expand Down
10 changes: 10 additions & 0 deletions docs_website/docs/integrations/add_auth.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ OAUTH_CLIENT_ID: '---Redacted---'
OAUTH_CLIENT_SECRET: '---Redacted---'
```

#### Auth0

```yaml
AUTH_BACKEND: 'app.auth.auth0_auth'
OAUTH_CLIENT_ID: '---Redacted---'
OAUTH_CLIENT_SECRET: '---Redacted---'
AUTH0_BASE_URL: https://[Redacted].[Redacted].auth0.com/
PUBLIC_URL: http://localhost:10001
```

:::caution
DO NOT CHECK IN `OAUTH_CLIENT_SECRET` to the codebase. The example above is for testing only. For production, please use environment variables to provide this value.
:::
Expand Down
36 changes: 36 additions & 0 deletions querybook/server/app/auth/auth0_auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import requests
from env import get_env_config

from app.auth.okta_auth import OAUTH_CALLBACK_PATH, OktaLoginManager


class NoopAuth(requests.auth.AuthBase):
jczhong84 marked this conversation as resolved.
Show resolved Hide resolved
"""
This auth doesn't do anything.
It only used to override oauthlib's behavior.
"""

def __call__(self, r):
return r


class Auth0LoginManager(OktaLoginManager):
def get_oauth_urls(self):
auth0_base_url = get_env_config("AUTH0_BASE_URL")
authorization_url = f"{auth0_base_url}/authorize"
token_url = f"{auth0_base_url}/oauth/token"
profile_url = f"{auth0_base_url}/userinfo"
return authorization_url, token_url, profile_url


login_manager = Auth0LoginManager()

ignore_paths = [OAUTH_CALLBACK_PATH]


def init_app(app):
login_manager.init_app(app)


def login(request):
return login_manager.login(request)
4 changes: 2 additions & 2 deletions querybook/server/app/auth/okta_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __call__(self, r):


class OktaLoginManager(OAuthLoginManager):
def get_okta_urls(self):
def get_oauth_urls(self):
okta_base_url = get_env_config("OKTA_BASE_URL")
authorization_url = f"{okta_base_url}/v1/authorize"
token_url = f"{okta_base_url}/v1/token"
Expand All @@ -38,7 +38,7 @@ def get_okta_urls(self):
@property
@in_mem_memoized()
def oauth_config(self):
authorization_url, token_url, profile_url = self.get_okta_urls()
authorization_url, token_url, profile_url = self.get_oauth_urls()

return {
"callback_url": "{}{}".format(
Expand Down