GitHub OAuth is commonly used to let users sign in to applications with their GitHub accounts. It is also used by developer tools, dashboards, integrations, and services that need permission to access GitHub resources on behalf of users.
For a long time, many applications relied on a single callback URL configured in their GitHub OAuth App settings. This worked well for applications with one production domain, but it created challenges when developers needed separate callback URLs for local development, staging, testing, and production.
GitHub has introduced several updates to its OAuth platform to improve redirect URI management and security. OAuth Apps can now register multiple redirect URIs, and developers can control wildcard matching for individual callback URLs. GitHub has also announced a change that will reject redirect URIs containing URL fragments starting February 1, 2027.
These changes require developers to review existing OAuth configurations and update their applications before the enforcement date.
This article explains the redirect URI changes, how to update a GitHub OAuth App, how to manage multiple environments, and how to test the authentication flow securely.
Understanding GitHub OAuth Redirect URIs
A redirect URI, also called a callback URL, is the address where GitHub sends a user after the user authorizes an application.
Consider an application that provides GitHub login. When a user selects the Sign in with GitHub option, the application redirects the browser to GitHub's authorization page.
After the user approves the requested permissions, GitHub redirects the browser back to the registered callback URL with a temporary authorization code.
For example:
https://github.com/login/oauth/authorize
?client_id=YOUR_CLIENT_ID
&redirect_uri=https://app.example.com/auth/github/callback
&scope=read:user,user:email
&state=RANDOM_STATE_VALUE
The important parameter is redirect_uri.
It tells GitHub where to send the user after authorization. GitHub checks the requested redirect URI against the callback URLs configured in the OAuth App settings.
If the requested URL does not satisfy the registered callback URL rules, GitHub can reject the authorization request.
How the OAuth Flow Works
The GitHub OAuth web application flow generally involves three main stages.
The application redirects the user to GitHub's authorization endpoint.
GitHub asks the user to authorize the requested permissions and redirects the user back with a temporary authorization code.
The application exchanges the authorization code for an access token and uses that token to access permitted GitHub resources.
The callback endpoint receives parameters similar to these:
https://app.example.com/auth/github/callback
?code=TEMPORARY_AUTHORIZATION_CODE
&state=RANDOM_STATE_VALUE
The authorization code is temporary and expires after a limited period. The application should validate the returned state value before exchanging the code.
The redirect URI must also be handled consistently during the authorization request and token exchange.
Understanding the Latest GitHub Redirect URI Changes
GitHub introduced several improvements to OAuth App and GitHub App redirect management in 2026.
These changes are important for applications that support multiple deployment environments or use dynamic tenant-based callback URLs.
Multiple Redirect URIs
GitHub OAuth Apps can now register up to 10 redirect URIs.
Previously, developers often maintained separate OAuth Apps for local development, staging, and production because each environment needed a different callback URL.
With multiple redirect URIs, one OAuth App can support several known callback addresses.
For example:
https://app.example.com/auth/github/callback
https://staging.example.com/auth/github/callback
https://dev.example.com/auth/github/callback
When multiple callback URLs are configured, the application should explicitly send the redirect_uri parameter in the authorization request.
This makes the intended destination clear and avoids relying on the first registered callback URL.
If the parameter is omitted, GitHub uses the first callback URL configured in the OAuth App settings.
Wildcard Matching for Redirect URIs
GitHub also introduced configurable wildcard matching for callback URLs.
When wildcard matching is enabled, a registered callback URL can match certain related subdomains and additional paths.
For example, consider this registered callback URL:
https://example.com/auth/callback
With wildcard matching enabled, GitHub can allow matching URLs such as:
https://example.com/auth/callback
https://example.com/auth/callback/tenant-a
https://oauth.example.com/auth/callback
However, wildcard matching does not allow every possible URL.
The host, excluding subdomains, and port must match the registered callback URL. The requested path must reference the registered path or a subdirectory of it.
For example, the following URLs would not match the registered callback:
https://example.com/another-path
https://example.com:8080/auth/callback
https://another-domain.com/auth/callback
Wildcard matching should be enabled only when the application genuinely needs it.
It can increase the attack surface because authorization codes may be redirected to additional subdomains or paths. If an attacker can control a matching subdomain or host user-generated content on it, the application may expose authorization codes to an untrusted destination.
GitHub also notes that OAuth Apps and certain older GitHub Apps had wildcard matching enabled by default to preserve previous behavior. Developers should review existing settings instead of assuming wildcard matching is disabled.
Deprecation of Redirect URI Fragments
GitHub announced another important change on November 30, 2026.
Starting February 1, 2027, GitHub.com will reject OAuth authorization requests that use redirect URIs containing URL fragments.
A URL fragment is the part of a URL that appears after the # character.
For example:
https://app.example.com/auth/callback#github
The fragment is not part of the HTTP request sent to the server. Browsers handle it on the client side.
OAuth redirect URIs containing fragments are not permitted by the OAuth 2.0 specification. They can also introduce security risks involving the exposure or interception of authorization codes and tokens during redirects.
The following callback URL should therefore be updated:
https://app.example.com/auth/callback#login
Use this instead:
https://app.example.com/auth/callback
The change applies to GitHub.com across Free, Team, and Enterprise Cloud plans. It does not apply to GitHub Enterprise Server.
Developers should remove fragments from both registered callback URLs and dynamically generated redirect_uri values before the enforcement date.
Review Your Existing GitHub OAuth App
Before changing application code, review the existing OAuth App configuration.
Open GitHub and navigate to:
Settings → Developer settings → OAuth Apps → Select your application.
Review the following settings:
Application name.
Homepage URL.
Authorization callback URL.
Registered redirect URIs.
Wildcard matching settings.
Client ID.
Client secret.
Check whether the existing callback URL contains a fragment.
For example:
https://app.example.com/oauth/callback#github
If it does, remove the fragment and update the application configuration.
Also identify all environments that use the OAuth App. A production application may work correctly while a staging or local development environment continues using an outdated callback URL.
Maintain a list of every callback URL used by the application before making changes.
Add Multiple Callback URLs to a GitHub OAuth App
If your application supports different environments, register each callback URL in the OAuth App settings.
For example, an application may use these three environments:
Environment | Callback URL |
|---|
Local development | http://localhost:8000/auth/github/callback
|
Staging | https://staging.example.com/auth/github/callback
|
Production | https://app.example.com/auth/github/callback
|
Open the OAuth App settings and add the required redirect URIs using the available redirect URI configuration.
GitHub supports up to 10 callback URLs for OAuth Apps.
After adding the URLs, review the wildcard matching option for each entry.
For most applications, exact callback matching is preferable. It limits the number of destinations that can receive authorization codes.
Use the Redirect URI Explicitly
When multiple callback URLs are configured, select the appropriate URL for the current environment.
For example, a development environment may use:
GITHUB_REDIRECT_URI = (
"http://localhost:8000/auth/github/callback"
)
Production can use:
GITHUB_REDIRECT_URI = (
"https://app.example.com/auth/github/callback"
)
Do not construct the callback URL directly from an untrusted HTTP request header.
For example, avoid using the incoming Host header to decide where GitHub should redirect the user. An attacker may manipulate host-related request values if the application and proxy configuration do not validate them correctly.
Use a trusted environment variable or application configuration instead.
Update the OAuth Authorization Request
The next step is to update the authorization request generated by your application.
The following Python example demonstrates how to build the GitHub authorization URL using a configured callback URL.
import os
import secrets
from urllib.parse import urlencode
GITHUB_CLIENT_ID = os.environ["GITHUB_CLIENT_ID"]
GITHUB_REDIRECT_URI = os.environ[
"GITHUB_REDIRECT_URI"
]
def create_github_authorization_url():
state = secrets.token_urlsafe(32)
params = {
"client_id": GITHUB_CLIENT_ID,
"redirect_uri": GITHUB_REDIRECT_URI,
"scope": "read:user user:email",
"state": state
}
authorization_url = (
"https://github.com/login/oauth/authorize?"
+ urlencode(params)
)
return authorization_url, state
The example uses environment variables to separate application configuration from source code.
The secrets.token_urlsafe() function generates a random state value for the authorization request.
In a real web application, store the state securely in the user's server-side session or a secure, appropriately configured cookie. Compare it with the returned state value when GitHub redirects the user back.
Do not simply generate a state value and trust the value returned by GitHub without checking it.
Validate the Callback and Exchange the Authorization Code
After the user authorizes the application, GitHub redirects the browser to the selected callback URL.
The callback endpoint should validate the state parameter and then exchange the authorization code for an access token.
The following example uses Flask to demonstrate the callback handling logic.
import os
import requests
from flask import (
Flask,
redirect,
request,
session,
abort
)
app = Flask(__name__)
app.secret_key = os.environ["FLASK_SECRET_KEY"]
CLIENT_ID = os.environ["GITHUB_CLIENT_ID"]
CLIENT_SECRET = os.environ["GITHUB_CLIENT_SECRET"]
REDIRECT_URI = os.environ["GITHUB_REDIRECT_URI"]
@app.route("/auth/github/callback")
def github_callback():
code = request.args.get("code")
returned_state = request.args.get("state")
expected_state = session.pop(
"github_oauth_state",
None
)
if (
not expected_state
or not returned_state
or returned_state != expected_state
):
abort(400, "Invalid OAuth state")
if not code:
abort(400, "Authorization code is missing")
token_response = requests.post(
"https://github.com/login/oauth/access_token",
headers={
"Accept": "application/json"
},
data={
"client_id": CLIENT_ID,
"client_secret": CLIENT_SECRET,
"code": code,
"redirect_uri": REDIRECT_URI
},
timeout=15
)
token_response.raise_for_status()
token_data = token_response.json()
if "error" in token_data:
abort(400, "GitHub token exchange failed")
access_token = token_data.get("access_token")
if not access_token:
abort(400, "Access token was not returned")
# Store the token securely using the application's
# established server-side token storage strategy.
return redirect("/dashboard")
This example demonstrates the main callback checks, but a complete application must also configure secure session cookies, CSRF protections, error handling, and secure token storage.
The callback URL supplied during token exchange should be consistent with the URL used in the original authorization request.
Do not expose the client secret or access token in application logs or browser responses.
Use PKCE to Strengthen OAuth Security
Proof Key for Code Exchange (PKCE) adds protection to the authorization code flow.
It uses two values:
The application later sends the original verifier during the token exchange.
This helps prevent an intercepted authorization code from being exchanged by an unauthorized party.
For an OAuth flow that supports PKCE, generate a verifier and an S256 challenge:
import base64
import hashlib
import secrets
def generate_pkce_values():
verifier = secrets.token_urlsafe(64)
digest = hashlib.sha256(
verifier.encode("ascii")
).digest()
challenge = base64.urlsafe_b64encode(
digest
).rstrip(b"=").decode("ascii")
return verifier, challenge
Include the challenge in the authorization request:
params = {
"client_id": GITHUB_CLIENT_ID,
"redirect_uri": GITHUB_REDIRECT_URI,
"scope": "read:user user:email",
"state": state,
"code_challenge": challenge,
"code_challenge_method": "S256"
}
During token exchange, send the original verifier:
data = {
"client_id": GITHUB_CLIENT_ID,
"client_secret": GITHUB_CLIENT_SECRET,
"code": code,
"redirect_uri": GITHUB_REDIRECT_URI,
"code_verifier": verifier
}
Store the verifier securely between the authorization request and callback. Never send the verifier in the browser redirect URL.
PKCE support and requirements depend on the GitHub application type and authorization flow. Verify the current GitHub documentation for the specific OAuth App or GitHub App flow before implementing it.
Configure Callback URLs Across Environments
A common migration mistake is hardcoding one callback URL in the application.
This creates problems when the same codebase runs in development, staging, and production.
A better approach is to use environment-specific configuration.
For example, maintain separate environment variables:
# Development
GITHUB_CLIENT_ID=development-client-id
GITHUB_CLIENT_SECRET=development-client-secret
GITHUB_REDIRECT_URI=http://localhost:8000/auth/github/callback
# Production
GITHUB_CLIENT_ID=production-client-id
GITHUB_CLIENT_SECRET=production-client-secret
GITHUB_REDIRECT_URI=https://app.example.com/auth/github/callback
For applications that use one OAuth App across multiple environments, register all required callback URLs and select the correct one through trusted configuration.
For applications with separate security boundaries, separate OAuth Apps may still be a better choice.
For example, a development application may have different permissions, credentials, and access policies from the production application.
The decision should depend on the application's deployment architecture and security requirements rather than simply trying to reduce the number of OAuth Apps.
OAuth Apps and GitHub Apps: Understand the Difference
GitHub OAuth Apps and GitHub Apps both support user authorization, but they are not interchangeable.
A GitHub OAuth App primarily acts on behalf of an authorized user using OAuth scopes.
A GitHub App provides more granular permissions and installation-based access to repositories and organizations. It can also request user authorization when needed.
Their callback configuration is similar in concept, but the registration and authorization workflows have important differences.
Feature | OAuth App | GitHub App |
|---|
Main authorization model | User authorization through OAuth scopes | Installation permissions and optional user authorization |
Callback configuration | OAuth callback URLs | User authorization callback URLs |
Multiple callback URLs | Up to 10 | Supports multiple callback URLs |
Wildcard matching | Configurable per callback URL | Configurable per callback URL |
Installation flow | Not based on GitHub App installation | Supports installation on accounts and organizations |
Permission model | OAuth scopes | Granular repository and organization permissions |
When updating an existing integration, first confirm whether it uses an OAuth App or a GitHub App.
Do not copy GitHub App installation instructions into an OAuth App migration without checking the relevant authorization flow.
Troubleshooting Common Redirect URI Problems
Redirect URI changes can introduce authentication errors if the application configuration and GitHub registration do not match.
Problem | Possible reason | Recommended solution |
|---|
redirect_uri_mismatch
| Requested URI does not match an allowed callback URL | Compare the exact registered and requested values |
Login works locally but fails in production | Production callback URL is missing or incorrect | Register and configure the production URL |
Authorization request is rejected | Redirect URI contains a URL fragment | Remove the fragment from the registered and requested URI |
Authorization code exchange fails | Token request uses a different redirect URI | Use the same configured URI used during authorization |
Callback works for one tenant but not another | Wildcard matching or callback path is not configured correctly | Review matching rules and tenant routing |
OAuth state validation fails | Session was lost, expired, or does not match | Verify secure session storage and state handling |
Staging redirects to production | Environment configuration is incorrect | Check deployment variables and application settings |
Fix redirect_uri_mismatch
GitHub returns a redirect_uri_mismatch error when the requested redirect URI does not satisfy the registered callback URL rules.
Check the following details:
Protocol: HTTP or HTTPS.
Domain and subdomain.
Port number.
Callback path.
URL encoding.
Trailing slash.
Query parameters.
URL fragment.
For example, these URLs are not necessarily equivalent:
https://app.example.com/auth/callback
https://app.example.com/auth/callback/
Keep the callback configuration consistent and avoid generating slightly different URLs in different parts of the application.
Fix Fragment-Related Errors
Search the application configuration for callback URLs containing #.
Also review frontend configuration, environment variables, deployment secrets, and OAuth authorization URL builders.
Remove fragments from every redirect URI used in the OAuth flow before February 1, 2027.
Do not replace a fragment with an arbitrary query parameter unless the application actually needs that parameter and handles it securely.
Fix Callback Errors After Deployment
A deployment may introduce a new domain or reverse proxy configuration.
For example, an application may be available externally through HTTPS while its internal application server receives HTTP requests from a proxy.
If the application generates callback URLs from the internal request scheme, it may accidentally send an HTTP redirect URI instead of the registered HTTPS URL.
Use a trusted, explicitly configured public callback URL rather than relying on automatically generated request URLs.
If the application must use forwarded headers, configure the trusted proxy correctly and ensure untrusted clients cannot spoof those headers.
Testing the Redirect URI Migration
Before releasing the updated OAuth configuration, test the complete authentication flow.
The following checklist covers the most important scenarios:
Verify that the production callback URL is registered.
Verify that the staging callback URL is registered.
Verify that local development uses the intended callback URL.
Confirm that no redirect URI contains a URL fragment.
Confirm that the correct callback URL is sent in the authorization request.
Confirm that the token exchange uses the same redirect URI.
Test the application with an invalid redirect URI.
Test the OAuth state validation.
Test authorization denial and callback error handling.
Verify that authorization codes and access tokens are not written to logs.
Confirm that wildcard matching is disabled unless required.
Test the login flow after deployment.
Also test the application with multiple registered callback URLs. This helps identify cases where the application accidentally uses the first registered callback instead of the intended environment-specific URL.
Best Practices for Managing GitHub OAuth Redirect URIs
Register only callback URLs that the application actually uses.
Remove URL fragments from callback URLs and authorization requests.
Use explicit redirect URI configuration for every environment.
Prefer exact callback matching over wildcard matching.
Enable wildcard matching only when the application architecture requires it.
Never build redirect destinations from untrusted request parameters or host headers.
Validate the OAuth state parameter on every callback.
Use PKCE where supported by the selected authorization flow.
Keep OAuth client secrets on the server and store tokens securely.
Avoid logging authorization codes, client secrets, and access tokens.
Use HTTPS for production callback URLs.
Test the complete authorization and token exchange flow after configuration changes.
Review GitHub's OAuth documentation and changelog before making future authentication changes.
Advantages and Disadvantages of Multiple Redirect URIs
Advantages | Disadvantages |
|---|
One OAuth App can support multiple environments | Callback configuration requires careful management |
Reduces the need for separate OAuth Apps in some architectures | Incorrect environment selection can cause login failures |
Supports different domains and deployment configurations | Up to 10 callback URLs are available |
Makes environment-specific redirects explicit | Wildcard matching introduces additional security considerations |
Simplifies some OAuth deployment workflows | Existing applications may need configuration and code updates |
Multiple redirect URIs make OAuth configuration more flexible, but developers still need to control which destinations are allowed and how the application selects them.
Conclusion
GitHub's redirect URI updates give developers more flexibility when managing OAuth authentication across different environments. Multiple callback URLs make it easier to support development, staging, and production with one OAuth App, while configurable wildcard matching provides additional flexibility for applications that need related subdomains or paths.
However, these features also make callback URL security more important.
The upcoming rejection of redirect URIs containing URL fragments on February 1, 2027, is a change developers should address before enforcement. Review existing OAuth App settings, remove fragments, register the required callback URLs, and update application configuration to use trusted redirect destinations.
For production applications, exact callback matching, secure state validation, PKCE where supported, protected client secrets, and complete authentication testing should remain part of the implementation.
A careful migration helps prevent unexpected GitHub login failures while keeping the OAuth authorization flow secure and predictable.
Join the conversation! Your thoughts help the community grow.