Skip to Content
GuidesConnect an existing tool

Connect an existing tool

Many tools you may already run, such as a help desk or a dashboard, have a login setting called generic OAuth or OpenID Connect. Point that setting at Foir and the people the tool signs in use the accounts they already have with you. The tool needs a client ID and a secret from Foir, and Foir’s issuer.

Where to register the tool

Register the tool as an auth client where the people who use it are:

The tool is forRegister it inPeople sign in with
A project’s usersThe project: the console’s Access, Sign-in, on the Auth clients tab, or foir.config.tsTheir account in that project
Your workspace’s teamThe workspace console’s Sign-in, on the Auth clients tabTheir Fóir account, then the project they choose

Then say who runs it. For a tool you run, turn on This project runs this app (This workspace runs this app in the workspace console, firstParty: true in a config), and nobody is asked to agree to it. Leave it off for a tool someone else runs: each person sees what it asks for on the consent page and agrees once. Consent has the detail.

Register it as a confidential app

A tool with a generic OpenID Connect login runs on a server, where it can keep a client secret, so it is registered as a confidential app.

  1. Add the auth client with the tool’s callback address as its redirect URI, and turn on Confidential app (keeps a client secret). In a config:

    defineAuthClient({ clientId: 'team-dashboards', name: 'Team dashboards', redirectUris: ['https://grafana.example.com/login/generic_oauth'], grants: [], firstParty: true, confidential: true, });

    grants: [] suits a tool that only needs to know who someone is. List permissions only if the tool calls Foir’s API with the token.

  2. Release it. A new auth client signs nobody in until a release carries it: Publish in the console, or foir push --publish.

  3. Make a secret, with Make a secret in the auth client’s form or foir auth-clients secrets create team-dashboards. Foir shows it once and keeps only its hash, so paste it into the tool straight away.

A config never carries a secret, and a push that names one is refused.

What to put in the tool

The tool asks forGive it
Issuer, or discovery URLhttps://api.foir.dev, or your project’s login domain if it has one (The issuer). The discovery URL is the issuer followed by /.well-known/openid-configuration.
Client IDThe auth client’s client ID.
Client secretThe secret you made.
Scopesopenid profile email
Client authenticationclient_secret_basic or client_secret_post. Tools call these Basic or “in header”, and “in body” or “in params”. Foir takes either.
Redirect or callback URLThe tool tells you this one. Register it on the auth client exactly as the tool shows it.
PKCEOptional for a confidential app. Turn it on if the tool offers it.

A tool that can’t read discovery asks for the endpoints one by one: authorization at {issuer}/oauth/authorize, token at {issuer}/oauth/token, userinfo at {issuer}/oauth/userinfo and keys at {issuer}/.well-known/jwks.json. The person’s email is in the ID token and in userinfo, and their name is too when the tool asks for profile.

Grafana

Proved on Grafana 13.0.2 (grafana/grafana-oss:13.0.2). In grafana.ini:

[server] root_url = https://grafana.example.com [auth.generic_oauth] enabled = true name = Foir client_id = team-dashboards client_secret = fcs_... scopes = openid email profile auth_url = https://api.foir.dev/oauth/authorize token_url = https://api.foir.dev/oauth/token api_url = https://api.foir.dev/oauth/userinfo use_pkce = true

Each setting can also be an environment variable, such as GF_AUTH_GENERIC_OAUTH_CLIENT_SECRET. Register the root_url followed by /login/generic_oauth as the redirect URI: https://grafana.example.com/login/generic_oauth here. Grafana’s login page then offers Foir by the name you gave it, and Grafana makes an account for each person from their email the first time they sign in.

Grafana signs people in without use_pkce too. Its auth_style can stay unset, or be InHeader (Basic) or InParams (post), and Foir takes each.

oauth2-proxy

oauth2-proxy  puts a sign-in in front of a tool that has none of its own. Proved on v7.15.5:

export OAUTH2_PROXY_CLIENT_SECRET=fcs_... export OAUTH2_PROXY_COOKIE_SECRET=$(openssl rand -base64 32 | tr -- '+/' '-_') oauth2-proxy \ --provider=oidc \ --provider-display-name=Foir \ --oidc-issuer-url=https://api.foir.dev \ --client-id=internal-tools \ --redirect-url=https://tools.example.com/oauth2/callback \ --scope="openid email profile" \ --code-challenge-method=S256 \ --email-domain='*' \ --upstream=http://127.0.0.1:8080

Register https://tools.example.com/oauth2/callback as the redirect URI. oauth2-proxy finds Foir’s endpoints by discovery and checks each ID token’s issuer, signature and audience. --code-challenge-method is optional. --email-domain='*' lets in everyone the auth client signs in; name domains instead to let in fewer.

Rotate the secret

An auth client can hold several secrets at once, so the tool’s secret changes without a gap:

  1. Make a new secret.
  2. Put it in the tool, and check that someone can sign in.
  3. Revoke the old one, in the auth client’s form or with foir auth-clients secrets revoke team-dashboards <id>.

foir auth-clients secrets list team-dashboards names each secret by its first characters and says when the tool last used it. Disabling the auth client, or binding it to another place, revokes every secret it holds, and the tool needs a new one after that.

When something goes wrong

What you seeWhyWhat to do
Foir’s page says “The app asked to send you back to an address it hasn’t registered”The address the tool sent isn’t one the auth client lists. It has to match exactly, down to the port and any trailing slash.Add the address the tool sends as a redirect URI.
Foir’s page says “This sign-in came from an app that isn’t registered here” (app_not_recognised)No release has carried the auth client yet, the client ID in the tool is wrong, or the auth client is disabled.Publish the auth client, and check the client ID.
The tool says it couldn’t get a token, and its log names invalid_client. Grafana shows “Failed to get token from provider”, and oauth2-proxy shows a 500 page.The secret is wrong or revoked, or the tool sends none.Make a new secret and put it in the tool.
Foir’s page says “invalid email or password” to someone who has an account with youThey aren’t one of the people this auth client signs in. A project’s users and your team are separate accounts, so a team member can’t sign in to a tool registered in a project.Register the tool where they are, or give them an account in the project.
The tool reports access_deniedThe person declined on the consent page. For a tool registered in your workspace, they may have no access to the workspace, or hold none of what the tool asks for.Mark the tool as one you run, or give them access.

Hosted sign-in lists every error Foir sends back to an app, and the OpenID Connect reference lists every endpoint.

Last updated on