kotsikau/gcp_service_account_auth

1.0.2
GCP Service Account Auth Mediation Policy

Overview

Request-flow Ballerina mediation policy for Bijira/API Platform. The policy obtains a Google OAuth2 access token with the service-account JWT assertion flow, caches the token in memory per mediation app instance, and sets the outbound backend request header:

Copy
Authorization: Bearer <access-token>

Policy Parameters

Configure these parameters when attaching the policy:

ParameterDescription
clientEmailGoogle service-account email. Use a deploy-time variable or secret such as ${GCP_CLIENT_EMAIL}.
privateKeyPEM RSA private key content. Use a secret such as ${GCP_PRIVATE_KEY}. Escaped \n values are supported.
tokenUriGoogle OAuth2 token endpoint. Blank values default to https://oauth2.googleapis.com/token.
scopeSpace-delimited OAuth scopes. Use a deploy-time variable such as ${GCP_SCOPE}.
refreshSkewSecondsNumber of seconds before expiry when the cached token should be refreshed. Non-positive values default to 300.

No filesystem paths, service-account JSON files, Java mediator JAR, Redis, or shared cache are used.

Build And Publish

Copy
bal pack
bal push

The published package is:

Copy
kotsikau/gcp_service_account_auth:1.0.1

API Platform Deployment

  1. Open the API proxy in Bijira/API Platform Console.
  2. Go to Develop -> Policies.
  3. Attach
    Copy
    kotsikau/gcp_service_account_auth:1.0.1
    to the Request flow.
  4. Configure the policy with deploy-time variables or secrets:
Copy
clientEmail = ${GCP_CLIENT_EMAIL}
privateKey = ${GCP_PRIVATE_KEY}
scope = ${GCP_SCOPE}
tokenUri = ${GCP_TOKEN_URI}
refreshSkewSeconds = 300

If no custom token endpoint is required, leave tokenUri blank when the console allows it.

Runtime Behavior

The policy logs cache hits, cache misses, token refresh starts, and token refresh completion. It never logs private keys, JWT assertions, or full access tokens. Token generation and exchange failures return clear mediation errors.

Import

import kotsikau/gcp_service_account_auth;Copy

Other versions

Metadata

Released date: 5 days ago

Version: 1.0.2


Compatibility

Platform: any

Ballerina version: 2201.13.3

GraalVM compatible: Yes


Pull count

Total: 2

Current verison: 0


Weekly downloads



Keywords

choreo-apim-mediation-policy

choreo-apim-mediation-request-flow

gcp

service-account

oauth2