Blog | G5 Cyber Security

Secure External App Access

TL;DR

This guide shows you how to let external applications access your systems securely using industry-standard authentication methods like OAuth 2.0 and OpenID Connect (OIDC). We’ll cover setting up an authorization server, registering your application, and handling the authentication flow.

1. Choose an Authorization Server

An authorization server manages user authentication and grants access to applications. Options include:

For this guide, we’ll assume you’re using a cloud provider like Auth0 due to its simplicity.

2. Register Your Application

  1. Create an application in your authorization server: In Auth0, go to ‘Applications’ and click ‘+ Create Application’.
  2. Configure the application settings:
    • Name: A descriptive name for your app.
    • Type: Select ‘Regular Web Applications’ or similar depending on your app’s architecture.
    • Allowed Callback URLs: The URL where Auth0 redirects users after authentication (e.g., https://your-app.com/callback). This is *critical* for security.
    • Allowed Logout URLs: Where Auth0 sends users after logout.
  3. Note the Client ID and Client Secret: These are essential credentials for your application to communicate with the authorization server. Keep them secure!

3. Implement the Authentication Flow (OAuth 2.0)

The standard OAuth 2.0 flow involves these steps:

  1. Redirect to Authorization Server: Your application redirects the user to the authorization server’s login page.
    https://your-auth0-domain.com/authorize?client_id=YOUR_CLIENT_ID&response_type=code&redirect_uri=https://your-app.com/callback&scope=openid profile email
  2. User Authentication: The user logs in at the authorization server.
  3. Authorization Code Grant: After successful login, the authorization server redirects the user back to your redirect_uri with an authorization code.

    Your application receives this code.

  4. Exchange Code for Token: Your application exchanges the authorization code for an access token (and potentially a refresh token).
    POST https://your-auth0-domain.com/oauth/token
    grant_type=authorization_code&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&code=AUTHORIZATION_CODE&redirect_uri=https://your-app.com/callback
  5. Use Access Token: Your application uses the access token to make authorized requests to your protected resources.

    Include the token in the Authorization header:
    Authorization: Bearer ACCESS_TOKEN

4. Handle Refresh Tokens

Access tokens expire. Use refresh tokens to obtain new access tokens without requiring the user to re-authenticate.

  1. Store the Refresh Token securely: Do not store it in client-side code!
  2. Request a New Access Token: When the access token expires, use the refresh token to request a new one.
    POST https://your-auth0-domain.com/oauth/token
    grant_type=refresh_token&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&refresh_token=REFRESH_TOKEN

5. Security Considerations

Exit mobile version