Next.js developer in Sheffield

Next.js for businesses in Sheffield, delivered remotely by one developer.

Next.js developer

My place in the WordPress community

  • I have had a wordpress.org account since 2006.
  • I contributed to WordPress core for versions 7.0 and 7.1.
  • I maintain 30 plugins on wordpress.org.
  • I organise and speak at WordCamps.
  • I have attended every WordCamp Europe from 2017 to 2026.

My WordPress.org profile

GOV.UK One Login is the sign-in and identity-checking system for government services. A Next.js service that uses it does not build a login form. It redirects the user to One Login, receives a code, exchanges it on the server and validates what comes back. I am not a government adviser and not a lawyer. This page follows the official technical documentation and states where I could not confirm something.

Palm trees and the timber arches inside the Winter Garden in Sheffield

Inside the Winter Garden in central Sheffield. Photo: Andrew Tryon, CC BY-SA 2.0, Wikimedia Commons.

#Who can use GOV.UK One Login?

The product information page is titled “Guide for services” and says: “You can try out GOV.UK One Login if you’re a central government service and need to sign in your users or check their identities.” The getting started page repeats it. Registering your interest starts the process, and the page says the team contacts you within 5 days. Trying the integration environment needs an admin tool account, which requires a government email address and a mobile phone number.

Neither page mentions local authorities, other public bodies or private companies. That matters in Sheffield, where a project can sit with a council, a university, an NHS body or a supplier. I do not read the silence as a yes or a no. If your client is not a central government department, the first question to the One Login team is whether the service is eligible at all, before any Next.js work.

#How does the One Login flow work?

The how it works page describes an OpenID Connect authorisation code flow:

  1. Your service fetches the discovery document from /.well-known/openid-configuration and caches it.
  2. Your service builds an authorize request, optionally as a signed JWT, and redirects the browser to /authorize. One Login fetches your public keys from your JWKS endpoint to check the request.
  3. The user signs in or creates an account. One Login redirects to your redirect URI with a single-use authorisation code.
  4. Your server sends a POST to /token with the code and a signed JWT assertion, and gets an ID token and an access token.
  5. Your server calls /userinfo with the access token to get user attributes.

In Next.js, steps 2 to 5 are server work. The browser only sees redirects.

#What does the authorize request need?

The authentication guide lists response_type (must be code), scope (must include openid), client_id, state, redirect_uri (must match your client configuration exactly) and nonce. Optional parameters include vtr for the authentication level, ui_locales with en or cy, claims for identity attributes, and a PKCE challenge if your client enforces it. Only S256 is supported for PKCE.

A Route Handler can build the redirect and keep state and nonce in a short-lived cookie. The Next.js cookies documentation allows setting cookies in a Route Handler:

// app/auth/login/route.ts
import { cookies } from 'next/headers'
import { redirect } from 'next/navigation'
import { randomUUID } from 'node:crypto'

export async function GET() {
  const state = randomUUID()
  const nonce = randomUUID()
  const store = await cookies()
  const opts = { httpOnly: true, secure: true, sameSite: 'lax' as const, maxAge: 600, path: '/' }
  store.set('oidc_state', state, opts)
  store.set('oidc_nonce', nonce, opts)

  const url = new URL(process.env.ONELOGIN_AUTHORIZE_URL!)
  url.search = new URLSearchParams({
    response_type: 'code',
    scope: 'openid email',
    client_id: process.env.ONELOGIN_CLIENT_ID!,
    redirect_uri: process.env.ONELOGIN_REDIRECT_URI!,
    state,
    nonce,
    vtr: '["Cl.Cm"]',
    ui_locales: 'en',
  }).toString()
  redirect(url.toString())
}

Read the authorize URL from the discovery document rather than hardcoding it. The documentation’s example for the integration environment is a discovery document at https://oidc.integration.account.gov.uk/.well-known/openid-configuration.

#How do the authentication levels work?

The authentication level page describes Cl as username and password, to use only if your service holds no personal information about users, and Cl.Cm as username and password plus a second step, by SMS one-time password or an authenticator app. Every service uses Cl.Cm by default unless it changes to Cl, and requesting identity attributes needs Cl.Cm. You send the choice as the vtr value.

#How does the token request work?

The server sends a POST to /token as application/x-www-form-urlencoded with grant_type=authorization_code, the code, the redirect_uri, a client_assertion_type of urn:ietf:params:oauth:client-assertion-type:jwt-bearer and a signed client_assertion. The assertion carries iss and sub set to your client ID, an aud of the token URL, an exp that the documentation recommends at 300 seconds, a unique jti and an iat. The documentation also says a User-Agent header is required and that a missing one gets a 403.

The signing key stays on the server, so this call can only live in a Route Handler or Server Function, never in a Client Component.

#What must I validate in the ID token?

The documentation says: “You must perform all of the validation described below, or your integration may not be secure.” The list:

  • Verify the signature with the key whose kid matches in the JWKS from the discovery document, and confirm the alg matches the key. If no kid matches, do not trust the token.
  • iss must match the issuer in the discovery document.
  • aud must contain your client ID.
  • The current time must be before exp and after iat.
  • nonce must match the one you sent.
  • vot must equal the trust level you requested. For Cl.Cm.P2 the documentation says to expect Cl.Cm.

A JOSE library does most of this for you. The documentation only advises checking whether your library supports ID token validation and does not name one. In the callback Route Handler, compare the returned state with the cookie first, then exchange the code, then validate, then create your own session.

#What does /userinfo return, and which ID should I store?

/userinfo takes the access token as a Bearer token and returns the user attributes you requested. sub is the unique user ID. The documentation advises against using sub or email as your primary user identifier and recommends mapping sub to your own internal ID. The Next.js authentication guide adds that a session payload should hold minimal data and no personally identifiable information, which fits: store your internal ID in the session cookie and the rest in your database.

Scopes follow the same restraint. openid is the only required scope, email and phone are optional, and identity claims such as core identity, address, passport and driving licence need identity confidence P2 or above. The documentation says you may only request claims covered by your Data Protection Impact Assessment.

#How long does a One Login session last?

The session guidance gives One Login a 1 hour timeout that starts at the user’s last interaction. It advises a service session of the same length or longer, and says every service should let users log out, because the One Login session cookie is persistent. The logout is a browser GET to the logout endpoint with id_token_hint (required if you use post_logout_redirect_uri), post_logout_redirect_uri and state.

Back-channel logout is optional but recommended. One Login sends a POST with a signed logout_token, and you validate its signature, iss, aud, iat, exp, sub, the events claim, and that the jti was not seen in the last 3 minutes. Then you close all sessions for that sub and answer 200. The URI must be reachable from the internet, so localhost does not work. In Next.js that means a Route Handler plus a session store that can be searched by sub, which makes database sessions the practical choice here.

#How do I test before touching the real service?

The documentation offers an integration environment and a simulator. The simulator stands in for the OpenID provider so you can build locally. It runs as a Docker image (ghcr.io/govuk-one-login/simulator:latest, port 3000) or from source, and can return chosen user data, simulate listed error cases and return identity responses without identity proving. The page states that it is not the real One Login and that you must test against the integration environment before going live.

In a Next.js repository that means an environment variable pointing the discovery URL at the simulator in local and CI runs, and at the integration environment in staging.

#What does going live involve?

The production page starts with governance: working with an Engagement Manager, signing a Memorandum of Understanding, considering fraud and security, and setting up analytics. Without an Engagement Manager, it says to register interest at least 6 weeks before go-live. Production setup is requested at least 10 days before beta use, with a stated service level of 10 working days. Production uses a new client ID, the production discovery endpoint and your production key, and the page says to connect to production only from your own service’s production environment.

Most of this is process on the client side, and it sets the schedule. A realistic plan puts the One Login governance steps in parallel with the build.

#Where do I start?

If your service is eligible, the first technical step is the integration environment and the simulator, with the callback route, ID token validation and logout built against them. For a Next.js service in this position, write to me through the contact page with the service type and the identity level you expect. The initial estimate arrives in writing at no charge, and the wider offer is on the Next.js developer page.

Need this service: Next.js developer in Sheffield?

Describe your project by e-mail. I reply within 24 hours.

Describe your project

Explore other WordPress services and knowledge base