Skip to content

Using AAF with OIDC

v 1.1

Ray Liu

Version Date Who Change Summary
1.0 Apr 2026 RL Created
1.1 Jul 2026 RL Scope guidance after feedback from Patrick at AAF

This guide shows how to register an Australian Access Federation (AAF) OpenID Connect service and connect it to a backend-owned login flow.

Use this guide when the frontend should initiate login, but the backend is the one that holds the AAF client secret, exchanges the authorization code, creates the application session, and returns only local session state to the browser.

This guide uses the Flask example using Python, for its code and deployment instructions. A companion Express example implements the same OIDC flow and route contract using Bun and TypeScript.

The AAF registration flow applies to both examples except where step 3 notes a different authentication method. Follow the companion example’s README for its Express-specific installation, configuration, and session guidance.

Have these ready:

  • AAF login access.
  • Permission to register a service for an AAF subscriber organisation.
  • For the Flask example, Python 3.11 or later and uv.
  • For the Express example, Bun 1.3.14 or later.
  • The URL where users start login.
  • The backend callback URL that AAF redirects to after login.

For the local demo:

URL: http://localhost:5000/
Redirect URL: http://localhost:5000/auth/callback

The screenshots and example registration values use The University of Melbourne. Substitute the organisation that owns your service and the IdP your users will select.

1. Confirm the IdP Is Available Through AAF

Section titled “1. Confirm the IdP Is Available Through AAF”

Before registering a service, confirm that the users’ organisation has an active Identity Provider (IdP) in AAF. There are two ways to check.

  1. Open the AAF subscribers page.
  2. Search for the organisation users will choose during institution discovery.
  3. Confirm that the expected organisation appears in the public directory.
AAF subscribers page showing participating organisations including The University of Melbourne.

The AAF subscribers page provides a quick public view of participating organisations.

The subscriber directory may lag behind the active federation metadata, and not every active IdP will necessarily appear there. Use the metadata explorer when the expected organisation is missing or when you want to confirm another organisation.

  1. Open the Australian Access Federation in the REFEDS Metadata Explorer.
  2. Confirm that the IDP entity type is selected.
  3. Search or browse the entity list for the organisation’s display name or IdP entity ID.
  4. Confirm that the organisation has an active IdP in the Australian Access Federation metadata.
REFEDS Metadata Explorer showing Identity Provider entities in the Australian Access Federation.

The REFEDS Metadata Explorer shows IdPs published in the Australian Access Federation metadata and can confirm organisations not shown in the public subscriber directory.

If neither source shows the expected organisation, pause production setup and confirm its federation access with the organisation or AAF Support. It may be available through eduGAIN or another federation path.

Use the AAF Test Federation first. The test service gives you a client identifier and client secret for local development.

  1. Open AAF Test Federation Manager.
  2. Select Login with the AAF.
  3. Select your organisation and continue the login process.
Federation Manager organisation selection page.

Select the organisation that lets you manage the service registration.

  1. On the Federation Manager dashboard, choose Connect a service.
Federation Manager dashboard with Connect a service highlighted.

The service registration starts from the Connect a service card.

  1. Choose OpenID Connect as the protocol.
Federation Manager connect new services page with OpenID Connect highlighted.

Choose OpenID Connect for this backend-owned login flow.

The registered AAF service represents the backend OIDC client. The frontend is still where users start, but the backend is the component that stores the secret and handles the callback.

For the local demo, fill the form with:

Name: OIDC Demo App
Description: A minimal local OpenID Connect demo application for testing AAF login with University of Melbourne users.
URL: http://localhost:5000/
Authentication methods: Secret
Redirect URL: http://localhost:5000/auth/callback
Organisation: The University of Melbourne

For the Flask example used throughout this guide, select Secret because the backend can store the client secret safely.

The Express example also uses PKCE, so select Secret and PKCE when registering a service for that implementation. If you test both authentication methods, use separate AAF client registrations so that each registration matches its implementation.

Do not put the client secret in frontend JavaScript.

Completed AAF service registration form for a localhost OIDC demo app.

The Flask backend serves both the frontend HTML and the API on the same port.

Select Register Service.

4. Save the Secret and Activate the Service

Section titled “4. Save the Secret and Activate the Service”

After registration, AAF shows the client secret once.

  1. Copy the secret immediately and store it in your backend .env file as AAF_CLIENT_SECRET.
  2. Review the service details.
  3. Select Activate.
Post-registration service page showing copy secret and activate actions.

Copy the secret before leaving the page, then activate the test service.

After activation, open the service details page.

Active registered OIDC service details page.

The service details page lets you review the active client configuration.

Copy the Identifier into your backend .env file as AAF_CLIENT_ID.

Registered service details showing the Identifier field used as the client ID.
The Identifier is the OIDC client ID.

AAF says new test services can take up to two hours before they can be used, so wait if the flow fails immediately after registration.

Open the registered service and select the Scopes tab.

If Selected Scopes is empty, Federation Manager uses all scopes from the incoming OIDC request. Explicitly selecting the minimum required scopes limits the user information that the AAF Central OIDC Proxy can release to the application.

Federation Manager Scopes tab showing no selected scopes and a list of available scopes.

This screenshot shows the initial empty state, which uses the default behavior. Add an explicit subset containing only the scopes the application needs.

For the local demo, add only:

  • openid for OIDC authentication and the signed-in user’s subject identifier.
  • profile for basic profile claims such as the user’s name.
  • email for email claims when the user’s home organisation provides them.

After adding them, confirm that all three appear under Selected Scopes. Scope changes may take up to two hours to appear on attribute-release consent pages.

These selections match the scopes requested by the backend in step 6. Do not add other scopes, such as the eduPerson scopes, unless the application has a documented requirement for those attributes.

Requesting a scope does not guarantee that every corresponding claim will be returned. The application must handle optional profile and email claims being absent when the user’s home organisation does not release them.

The Flask backend is the OIDC Relying Party for the Flask example. It starts the AAF redirect, handles the callback, exchanges the authorization code for tokens, reads user claims, and creates the application session cookie.

Dependencies are declared in pyproject.toml, so uv manages the local Python environment on first run.

[project]
dependencies = [
"authlib",
"flask",
"python-dotenv",
"requests",
]

Create local configuration:

Terminal window
cd example-projects/aai-aaf-python
cp .env.example .env
uv run python -c "import secrets; print(secrets.token_urlsafe(32))"

Fill in .env:

FLASK_SECRET_KEY=<generated-secret>
AAF_CLIENT_ID=<identifier-from-aaf>
AAF_CLIENT_SECRET=<secret-from-aaf>
AAF_DISCOVERY_URL=https://central.test.aaf.edu.au/.well-known/openid-configuration
AAF_REDIRECT_URI=http://localhost:5000/auth/callback

The backend loads those values before Flask starts:

load_dotenv()
REQUIRED_ENV_VARS = [
"FLASK_SECRET_KEY",
"AAF_CLIENT_ID",
"AAF_CLIENT_SECRET",
"AAF_DISCOVERY_URL",
"AAF_REDIRECT_URI",
]

Register AAF with Authlib using the discovery URL and requested scopes:

oauth.register(
name="aaf",
client_id=config["AAF_CLIENT_ID"],
client_secret=config["AAF_CLIENT_SECRET"],
server_metadata_url=config["AAF_DISCOVERY_URL"],
client_kwargs={
"scope": "openid email profile",
"token_endpoint_auth_method": "client_secret_post",
},
)

Start login by redirecting the browser to AAF:

@app.get("/auth/login")
def login():
return oauth.aaf.authorize_redirect(config["AAF_REDIRECT_URI"])

Handle the callback by exchanging the code and storing minimal claims in the session:

@app.get("/auth/callback")
def auth_callback():
token = oauth.aaf.authorize_access_token()
userinfo = token.get("userinfo") or oauth.aaf.userinfo(token=token)
session["user"] = {
"sub": userinfo.get("sub"),
"name": userinfo.get("name"),
"email": userinfo.get("email"),
"preferred_username": userinfo.get("preferred_username"),
}
return redirect("/?view=protected")

The runnable Flask and Express examples also expose raw_claims so developers can inspect the AAF response during local testing. This is development-only behavior. Remove raw_claims before production and retain only the claims the application needs.

Run the backend:

Terminal window
uv run app.py

Open:

http://localhost:5000

The frontend HTML lives in templates/index.html and is served by Flask at GET /. Because the browser and the API share the same origin, there is no cross-origin setup required.

Start login with a browser redirect. This keeps the OAuth flow out of frontend state:

function startLogin() {
window.location.href = "/auth/login";
}

Use relative paths and same-origin credentials for API requests so Flask can read the session:

async function fetchMe() {
const response = await fetch("/api/me", {
credentials: "same-origin",
});
return response.json();
}
Local AAF OIDC demo login page with a Login with AAF button.

The static frontend starts the login flow by redirecting the browser to the Flask backend.

  1. Open http://localhost:5000.
  2. Select Login with AAF.
  3. Confirm that AAF redirects to http://localhost:5000/auth/callback.
  4. Confirm that the backend redirects the browser to http://localhost:5000/?view=protected.
  5. Confirm that the protected view shows user claims from /api/me.
Local AAF OIDC demo protected view showing a signed-in session and returned user claims.

After the callback succeeds, the frontend reads the Flask session through backend APIs and displays the returned claims.

Check these first if login fails:

  • The Redirect URL registered in Federation Manager at step 3 must exactly match AAF_REDIRECT_URI in the .env file.
  • The test service has finished provisioning.
  • The backend has the current client identifier and secret.
  • The backend requests only scopes allowed for the service.
  • Frontend fetch calls use credentials: "same-origin".
  • The Flask example’s session cookie is not blocked by browser settings.

Discussion: Deploying the Flask Example Beyond the Local Demo

Section titled “Discussion: Deploying the Flask Example Beyond the Local Demo”

This section covers the Flask example. Treat cloud deployment as a separate design decision because it changes URLs, secrets, cookies, CORS, monitoring, and the AAF registration. For Express-specific configuration and session requirements, refer to the Express example README.

Choose stable HTTPS URLs before registering a production AAF service.

The simplest approach keeps frontend and backend on the same domain, the same way the local demo does:

URL: https://app.example.org/
Redirect URL: https://app.example.org/auth/callback

Then update backend configuration:

AAF_DISCOVERY_URL=https://central.aaf.edu.au/.well-known/openid-configuration
AAF_REDIRECT_URI=https://app.example.org/auth/callback

If you later separate the frontend to its own CDN origin (for example S3 + CloudFront at https://app.example.org with the API at https://api.example.org), that becomes a cross-origin deployment. You will need to add flask-cors back, configure CORS(app, origins=["https://app.example.org"], supports_credentials=True), and switch fetch calls back to credentials: "include". Register the public frontend URL in AAF as the service URL and update AAF_REDIRECT_URI to the API callback.

On AWS, a typical backend path is ECS Fargate, App Runner, Elastic Beanstalk, or Lambda behind API Gateway if the Flask app is adapted for Lambda. Put it behind HTTPS using ACM with an Application Load Balancer, CloudFront, or API Gateway.

Store these values outside the image and inject them at deploy time:

FLASK_SECRET_KEY
AAF_CLIENT_ID
AAF_CLIENT_SECRET
AAF_DISCOVERY_URL
AAF_REDIRECT_URI

Use AWS Secrets Manager or SSM Parameter Store for AAF_CLIENT_SECRET and FLASK_SECRET_KEY. Build from pyproject.toml; once dependency versions are final, commit and deploy with uv.lock.

For Google Cloud, the equivalent options are Cloud Run, App Engine, or GKE with secrets stored in Secret Manager.

When Flask serves the frontend (the same-origin approach), the HTML in templates/index.html is deployed with the backend container. On AWS that is ECS Fargate, App Runner, Elastic Beanstalk, or Lambda with a web adapter. On Google Cloud that is Cloud Run or App Engine.

The frontend uses relative paths, so no URL configuration is needed:

window.location.href = "/auth/login";
await fetch("/api/me", { credentials: "same-origin" });

Do not store AAF access tokens, ID tokens, or the AAF client secret in browser storage.

For production HTTPS, update the backend session configuration:

app.config.update(
SESSION_COOKIE_HTTPONLY=True,
SESSION_COOKIE_SAMESITE="Lax",
SESSION_COOKIE_SECURE=True,
)

No CORS configuration is needed when the frontend is served from the same origin as the API. If you later move the frontend to a separate CDN origin, add flask-cors and configure CORS as described in the production URL shape note above.

Register production only after the public URLs are stable.

  1. Open AAF Production Federation Manager.
  2. Register a new OpenID Connect service.
  3. Use the production application URL as the service URL and the callback as the Redirect URL.
URL: https://app.example.org/
Redirect URL: https://app.example.org/auth/callback
Authentication Methods: Secret
Organisation: <your AAF subscriber organisation>

Copy the production Identifier and Secret into the production secret store, allow the required scopes, and wait for organisational or AAF approval before testing production login.

When deploying the Express example instead, register it with Secret and PKCE to match its authorization request.

Before handing the service to users:

  1. Record the AAF service name, owner, redirect URIs, and scopes.
  2. Record where AAF_CLIENT_SECRET and FLASK_SECRET_KEY are stored.
  3. Document who can rotate the AAF secret.
  4. Add a smoke test for /auth/login, /auth/callback, /api/me, protected routes, and logout.
  5. Keep only the claims required by the application in its session.
  6. Remove development-only raw_claims storage and display.