Scope attributes

Overview


This document explains scope attributes. 


Scope attributes


A scope attribute is a key-value pair that is associated with a scope. The key and value of a scope attriubte are string values and each scope can have multiple scope attributes. 

How to create scope attributes


You can create scope attributes at Service Owner Console as below.

1. Open the edit page for your service at Service Owner Console.

2. Click "Create Scope" button to open a dialog box for creating a new scope.

3. Click "New Attribute" button.

4. Input the key and the value of the attribute and then click "Create" button.
Create a new scope attribute at Service Owner Console

Special scope attributes


The scope attributes listed below are reserved attributes, which have special meanings at Authlete.
Attribute key
Attibute value
Description
access_token.duration
number
This attribute is used to configure access token duration for each scope. For more details, see "Configure duration of access tokens and refresh tokens for each scope".
refresh_token.duration
number
This attribute is used to configure refresh token duration for each scope. For more details, see "Configure duration of access tokens and refresh tokens for each scope".
fapi
r
This is used to enable FAPI read-only API profile on Authlete. For more details see "How to use FAPI feature".
fapi
rw
This is used to enable FAPI read-and-write API profile on Authlete. For more details see "How to use FAPI feature".



How to use scope attributes


Scope attributes can be used in many use cases. The following sample code processes scope attributes when a response from Authlete /api/authorization API is returned.

// Call Authlete /api/authorization API.
AuthorizationResponse res = callAuthorizationAPI();

// Get scopes contained in the original authorizaiton request.
Scope[] scopes = res.getScopes(); 

if (scopes == null || scopes.length() == 0)
{
    return;
}

// Check each scope's attributes.
for (Scope scp in scopes)
{
    // Get the scope attributes of the scope.
    Pair[] attributes = scp.getAttributes();

    if (attributes == null || attributes.length() == 0)
    {
        continue;
    }

    // Check each attributes.
    for (Pair attr in attributes)
    {
        // The key of the attribute.
        String key = attr.getKey();

        // The value of the attirbute.
        String value = attr.getValue();

        // If the key is the target one.
        if ("targetkey".equals(key))
        {
            // Do something with the value.
            doSomething(value);
        }
    }
}

How did we do with this article?