Using service accounts

A Secure Web Sessions service account enables you to use the SWS API to authenticate to SWS and access data.

When you create a service account, a new public/private key pair is generated and downloaded to your machine. This is the only copy of the private key. You are responsible for storing the private key securely. Note its location and ensure the key is accessible to your application; it needs the key to make authenticated API calls.

Before you begin

You need to be a SWS Admin to create a service account.

Create a service account

  1. In the Secure Web Sessions portal, go to Identities > Service accounts.

  2. Click the Create service account button.

  3. Set the following properties:

    Property

    Description

    Name The name of the service account. This name appears in the activities performed with this account.
    Description A description of the service account. This appears in the service accounts list.
    Role

    Choose a role for the service account that defines its permissions.

    • Administrator - Can perform all actions and view all tenant information.
    • Auditor - Can only perform GET actions on Activities.
    • Viewer - Can perform GET actions on all tenant information, but not create/modify.
    Status

    The status of the new service account.

    Confirmation

    Select the check box to confirm that you want to create a service account.

  4. Click Save to create the .json file that is required to make the API calls, and save it on your computer. The .json file contains the following:

    • Service Account ID

    • Private key

    • DiscoveryURL

    The following example shows the contents of the .json file.

     
    {
        "serviceAccountId": "11ea6140f94d5f82a3712de9ac6f6b24",
        "privateKey": "-----BEGIN RSA PRIVATE KEY-----MIIEowIBAAKCAQEAhmfhZYpMev5bfrFDCyJmvKIHPL/0OkDhTicXZHd37uhTK8MNzKdY2+ohApYbF/grS7U6+bLEBs2PoLd4Eqv/cj89CI5VCaZlf5jeHPM4mys39QpJ1ljo8PqJN/sn8ZUXG/CH6Nalx+3DRdYauXPLGOJ5p4w1HyGIPSLAzaUnrg8oE4xZmR1UVFDh8Zqv+ORVIlx4SdIxs8cLgKc2G2DYqQerig8a7fDrIsJeaRyjsFN451N45JVEpMEpkOCN7XDufgJrMSN1iPQXgi4ACLEpa1xVPdMYaTnrAJ3saU71i0afL+7i6x/lhF7GRAEskGG+LYQe8U+VBHHgtN7vLuHtvwIDAQABAoIBAAssze/MXOmJBoB1KpbdaF9ctW9Wom7JgDIoS+idikpB5NBpqlcOvvOh9tapNl1609a6ncmvFF9gbgW123Tp+hY8rc1tUCK6RAwk4KrViipUoJVuIo+A2vVW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nxa6Y41l+cIJ7EFypEnndvsht/P6gRb-----END RSA PRIVATE KEY-----",
        "discoveryURI": "https://auth.alero.io/auth/realms/serviceaccounts/.well-known/openid-configuration"
    }

Prepare to make an API call

After you create the .json file in the Secure Web Sessions portal, and you have the Service Account ID and private key, do the following:

  1. Create a JSON Web Token (JWT), which includes a header, a claim set, and a signature. For more information, see Create a JSON Web Token (JWT).

  2. Request an access token from the token endpoint of the Secure Web Sessions Authorization Server. For more information, see Access token request.

  3. Handle the JSON response that the Authorization Server returns.

  4. Call APIs using the Access Token received from the Authorization Server. For more information, see Call Secure Web Sessions APIs

Create a JSON Web Token (JWT)

Secure Web Sessions authenticates clients with a Private Key JWT Client Authentication method (private_key_jwt), which is defined in OpenID Connect 1.0 and the JWT Profile for OAuth 2.0 Client Authentication specifications. This is an authentication method that can be used by clients to authenticate to the authorization server when using the token endpoint. Only clients that have registered a public key in the Secure Web Sessions portal (by creating a service account) and have signed a JWT using a matching private key (in the file downloaded when creating a service account) can authenticate.

When Secure Web Sessions authenticates clients with Private Key JWT Client Authentication, the clients send a request that contains an assertion in JWT format to the token endpoint of the server. Secure Web Sessions validates the signature and the payload of the assertion.

Although your application can complete these tasks by interacting directly with OAuth 2.0 using HTTP, server-to-server authentication interactions require applications to create and cryptographically sign JSON Web Tokens (JWTs). We recommend to avoid any impact on the security of your application by using libraries that abstract the cryptography away from your application code.

JWT structure

A JWT is composed of three parts: a header, a claim set, and a signature. The header and claim set are JSON objects. These JSON objects are serialized to UTF-8 bytes, then encoded using the Base64url encoding. The header, claim set, and signature are concatenated together with a period (.) character.

A JWT is composed of the following parts:

 
{Base64url encoded header}.{Base64url encoded claim set}.{Base64url encoded signature}

Access token request

After generating the signed JWT, an application can use it to request an access token.

This access token request is an HTTPS POST request, and must include the following parameters:

Parameter

Description

grant_type

client_credentials

client_assertion_type

urn:ietf:params:oauth:client-assertion-type:jwt-bearer

client_assertion

A signed JWT that contains information for client authentication

If the JWT and access token request are properly formed, and the service account has permission to perform the operation, the JSON response from the Authorization Server includes an access token.

Access tokens can be reused until during the duration noted in the expires_in value.

Call Secure Web Sessions APIs

After your application obtains an access token, use the token to make calls to a Secure Web Sessions API on behalf of a service account. Include the access token in a request to the API by including an Authorization: Bearer <AccessToken> HTTP header. In most cases, you can use a client library to set up your calls to Secure Web Sessions APIs.