Authentication for Developers
Authentication and Authorization Using OAuth, MBARI AD and SuperTokens
---
title: Authentication and Authorization Using OAuth, MBARI AD and SuperTokens
---
flowchart LR
subgraph SuperTokens
postgresql(PostgreSQL)
supertokens-core(Core)
supertokens-dashboard(/auth/dashboard)
end
subgraph backend
mssql-db[(MiniROV DiveLog DB)]
subgraph nodejs
env(.env)
express(Express App)
ssl(SSL)
database-connection(DB Connection)
openapi-rest(OpenAPI REST)
rest-endpoint(/rest)
swagger-ui(Swagger UI)
graphql(GraphQL Server)
graphql-endpoint(/graphql)
graphql-sandbox(GraphQL Sandbox)
supertokens-sdk(SuperTokens SDK)
auth-endpoints(/auth)
end
end
subgraph VueJS Frontend
dive-store(Dive Store REST)
user-store(User Store)
access-token(Access Token)
graphql-client(Dive GraphQL)
supertokens-client-sdk(SuperTokens Client SDK)
ui-components(UI Components)
end
subgraph oauth-providers
mbariad-cisco-duo
github
end
mssql-db --> database-connection
database-connection --> express
express --> ssl
ssl --> openapi-rest
openapi-rest --> rest-endpoint
openapi-rest --> swagger-ui
env --> openapi-rest
ssl --> graphql
graphql --> graphql-endpoint
graphql --> graphql-sandbox
env --> graphql
supertokens-core --> supertokens-sdk
supertokens-sdk --> auth-endpoints
mbariad-cisco-duo --> supertokens-core
github --> supertokens-core
postgresql --> supertokens-core
supertokens-core --> supertokens-dashboard
supertokens-client-sdk <--> github
supertokens-client-sdk <--> mbariad-cisco-duo
supertokens-client-sdk --> user-store
supertokens-client-sdk <--> auth-endpoints
user-store --> access-token
access-token --> dive-store
access-token --> graphql-client
rest-endpoint --> dive-store
graphql-endpoint --> graphql-client
access-token --> ui-components
Telepresence/Slack Authorization
The Telepresence application uses OAuth and Slack as an authentication mechanism because it needs to be able to represent users to Slack from the API backend (on their behalf).
Steps:
- Register application with Slack
- You provide:
- Redirect URL(s)
- User scopes
- identity.avatar
- identity.basic
- identity.email
- openid
- Bot scopes
- channels:history
- channels:join
- channels:manage
- chat:write
- chat:write.public
- commands
- groups:history
- im:history
- mpim:history
- users:read
- Slack provides:
- App ID
- Client ID
- Client Secret
- Signing Secret
- Verification Token
- App level token
- telepresence-dev-app-token = connections:write
- User OAuth token
- Bot User OAuth token
- Login button HTML
- You provide:
---
title: Telepresence Authentication
---
sequenceDiagram
Browser->>GraphQL API: Get app code
GraphQL API-->>Browser: HTML/CSS/JS
Browser->>Slack: /oauth/v2/authorize
Slack-->>Browser: Prompt for login
Browser->>Slack: Login
Slack-->>Browser: Prompt for user info access
Browser->>Slack: Allow
Slack-->>Browser: Redirect with code
Browser->>GraphQL API: /api/v1/rest/auth-callback
GraphQL API->>Slack: slack.com/api/oauth.v2.access (code, clientID, etc.)
Slack-->>GraphQL API: access token
GraphQL API->>Slack: slack.com/api/openid.connect.userInfo (with access token)
Slack-->>GraphQL API: user info(name, email, picture, etc.)
GraphQL API-->>Browser: Redirect to slack.com/oauth/v2/authorize
Browser->>Slack: slack.com/oauth/v2/authorize (with user access proxy requests)
Slack-->>Browser: Ask user for permission to represent
Browser->>Slack: Allow
Slack-->>Browser: Redirect to telepresence.mbari.org/api/v1/rest/auth-callback-2 (with code)
Browser->>GraphQL API: telepresence.mbari.org/api/v1/rest/auth-callback-2 with code from Slack
GraphQL API->>Slack: slack.com/api/oauth.v2.access (code, clientID, etc.)
Slack-->>GraphQL API: access token
GraphQL API-->>Browser: Redirect to /login?access-token=xxxxx (saves token in browser)
Slack button HTML
<a href="https://slack.com/oauth/v2/authorize?client_id=4525206644.2730768730532&scope=channels:history,channels:join,channels:manage,chat:write,chat:write.public,commands,groups:history,im:history,mpim:history,users:read&user_scope=email,identity.avatar,identity.basic,identity.email,openid"><img alt="Add to Slack" height="40" width="139" src="https://platform.slack-edge.com/img/add_to_slack.png" srcSet="https://platform.slack-edge.com/img/add_to_slack.png 1x, https://platform.slack-edge.com/img/add_to_slack@2x.png 2x" /></a>
Login URL:
https://slack.com/oauth/v2/authorize?
user_scope=email,identity.avatar,identity.basic,identity.email,openid
&client_id=4525206644.2730768730532
&redirect_uri=https://telepresence.mbari.org/api/v1/rest/auth-callback
&team=04FF62JY
Walkthrough:
- Redirect 1: https://mbari.slack.com/oauth?client_id=4525206644.2730768730532&scope=&user_scope=email%2Cidentity.avatar%2Cidentity.basic%2Cidentity.email%2Copenid&redirect_uri=https%3A%2F%2Ftelepresence.mbari.org%2Fapi%2Fv1%2Frest%2Fauth-callback&state=&granular_bot_scope=1&single_channel=0&install_redirect=&tracked=1
- Click Allow:
-
Redirect back to app: https://telepresence.mbari.org/api/v1/rest/auth-callback
- Click Alow:
- Redirect back to https://telepresence.mbari.org/api/v1/rest/auth-callback-2?code=4525206644.6563253540403.90872ef0043d9f287d14fd72ec8653d72bf84c5a136a530eabb74fbaeab39748&state=