The European Space Agency
Home
APEx Application Propagation Environments
Main navigation
  • Algorithm Services
  • Project Environments
    Web Portal
    Geospatial Explorer
    Documentation Hub
    User Forum
    Product Catalogue
    Collaborative Workspaces
  • Resources
    • Algorithm Services Catalogue
    • Data Catalogue
  • Documentation
  • FAQ
  • About APEx
  • News
Contact us
Main navigation
  • Algorithm Services
  • Project Environments
  • Resources
  • Documentation
  • FAQ
  • About APEx
  • News
APEx - Documentation Portal
  1. Guides
  2. Creating APEx single sign-on token
  • Welcome
  • On-demand EO services
    • Using openEO service
    • APEx-Compliant Platforms
  • Project Tools
    • Use Cases
    • Geospatial Explorer
    • Project Portal
    • User Workspace
    • Interactive Development Environment
    • Product Catalogue
    • Documentation Portal
    • User Forum
  • Algorithm Services
    • On-Demand EO Services
    • Use Cases
    • Algorithm Porting
    • Algorithm Onboarding
    • Algorithm Upscaling
    • Algorithm Enhancement
    • Toolbox Cloudification
    • Algorithm Intercomparison
  • Guides
    • Creating an APEx account
    • Creating APEx single sign-on token
    • Creating openEO based services
    • Creating EOAP based services
    • Upscaling openEO based services
    • Ingesting STAC metadata in APEx Product Catalogue
    • Linking APEx STAC catalogue with an openEO service
    • File format recommendations
    • Project Portal - User Documentation
      • Login to the Project Portal and the Drupal content overview
      • Manage web pages or add a new page
      • Edit web pages via paragraphs
      • Add content and/or visuals
      • Add a Call-To-Action (CTA)
      • Add news items and an overview of the latest or all news
      • Add an event and an overview of the latest or all events
      • Add a web form
      • Edit the menu navigation
      • Edit the footer
  • Interoperability and Compliance Guidelines
    • Definitions & Actors
    • Algorithm Service Development Options
    • Algorithm Developer and Provider Guidelines
    • Algorithm Hosting Platforms Guidelines
    • Geospatial Explorer
    • Federated Business Model
  1. Guides
  2. Creating APEx single sign-on token

Using the APEx Single Sign-On

APEx provides secure single sign-on (SSO) for all its instantiation services, supporting projects in implementing security best practices.

For services with a user interface, the login is straightforward. However, direct integration with APIs requires obtaining OIDC bearer token. This guide documents different approaches for generating a bearer token in a secure manner.

Interactive login from scripts & command line

The most secure login method involves an interactive login, and avoids storage of account credentials in scripts or on your personal device. This is the recommended default method.

Token generation via OIDC Agent

The oidc-agent CLI tool and its corresponding Python library allow you to integrate secure OIDC token generation into your scripts. The tool provides installation instructions for various operating systems.

The following instructions show how to generate a token on a Linux operating system, which is provided by the APEx User Workspace.

1. Start oidc-agent-service

The first step is to ensure that the oidc-agent-service is correctly running on your system.

eval `oidc-agent-service start`

2. Generate your project configuration

Now add a configuration for your project. This requires that you request a client ID from the APEx support team.

You will need to provide the following project specific information:

  • apex_project_a is simply the name of the configuration in OIDC agent, which you’ll use whenever you need a token.
  • the client id, which in this example is: project-a-catalogue-dev-api

Adjust these inputs in the following command, and run it to generate a new configuration. This step only needs to happen once per device where you want to set up the agent.

oidc-gen --pub apex_project_a --flow=device --client-id=project-a-catalogue-dev-api --iss=https://auth.apex.esa.int/realms/apex --scope=openid --redirect-url=""

3a. Generate a token from command line

From now on, whenever an OIDC bearer token is needed, you can run the following command:

oidc-token apex_project_a

3b. Generate a token from a Python script

With the configuration in place and the service running, you can now securely request a token from within scripts. When needed, this will trigger interactive authentication, but it will try to avoid this as much as possible via the use of ‘refresh tokens’.


import liboidcagent as agent

token, issuer, expires_at = agent.get_token_response("apex_project_a")

Machine to machine login via client credentials

While the interactive login is the most secure option, sometimes you require a long running script script or service to interact with an instantiation service like the catalog. In this case, you can use the client credentials flow, which is basically a username/password login for machines.

It is recommended to create such client credentials for each service separately, with minimal privileges. This allows you to retain granular access control, and to revoke access to a specific service without affecting others.

To obtain the client credentials, you currently need to contact the APEx support team.

The Python script below demonstrates how to obtain a token using the client credentials flow, which comes down to a very simply http request that can also be performed easily via curl or other tools.

import requests, os
scopes = ["openid", "roles" ]
token_response = requests.post(
    "https://auth.apex.esa.int/realms/apex/protocol/openid-connect/token",
    data={
        "grant_type": "client_credentials",
        "client_id": os.environ["APEX_CLIENT_ID"],
        "client_secret": os.environ["APEX_CLIENT_SECRET"],
        "scope": " ".join(scopes),
    }
).json()
access_token = token_response["access_token"]
Creating an APEx account
Creating openEO based services