Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public interface OAuth2AuthorizationService
Known subtypesInMemoryOAuth2AuthorizationService, JdbcOAuth2AuthorizationService
Where an authorization server keeps the grants it has made and the secrets it issued under them.
A secret – an authorization code, a refresh token, a device code, a user
code – is never stored: its SHA-256 is, see
OAuth2Parameters.sha256. And a
secret that works once is used up by consumeToken, which an
implementation must make one conditional statement on one row, never a read
followed by a write: several processes may share the store, and of two that
present the same code at the same moment exactly one may be told yes.
This is not the interface of Spring Authorization Server’s service of the
same name, whose save and findByToken leave that atomicity to the
caller.
Nested types
class OAuth2AuthorizationService.StoredToken | One stored secret, as OAuth2AuthorizationService.findToken reports it. |
Fields
public static final String CODE = "code" | The kind of an authorization code. |
public static final String REFRESH_TOKEN = "refresh_token" | The kind of a refresh token. |
public static final String DEVICE_CODE = "device_code" | The kind of an RFC 8628 device code. |
public static final String USER_CODE = "user_code" | The kind of an RFC 8628 user code. |
Methods
Field details
CODE
public static final String CODE = "code"REFRESH_TOKEN
public static final String REFRESH_TOKEN = "refresh_token"DEVICE_CODE
public static final String DEVICE_CODE = "device_code"USER_CODE
public static final String USER_CODE = "user_code"Method details
save
public abstract void save(OAuth2Authorization authorization)authorization, in place of the one with its id if there is one.findById
public abstract OAuth2Authorization findById(String id)remove
public abstract void remove(String id)addToken
public abstract void addToken(String authorizationId, String kind, String tokenHash, long expiresAt)Parameters
authorizationIdString- Not documented.
kindStringCODE,REFRESH_TOKEN,DEVICE_CODEorUSER_CODEtokenHashString- the SHA-256 of the secret
expiresAtlong- epoch milliseconds
issueTokens
public default boolean issueTokens(String authorizationId, long now, long expiresAt, String refreshTokenHash, boolean reuse)remove, including across server processes.
A removed grant must never be recreated. Custom stores must implement this
operation before issuing user tokens; the default fails closed.Parameters
authorizationIdString- Not documented.
nowlong- Not documented.
expiresAtlong- Not documented.
refreshTokenHashString- null when no refresh token is issued
reuseboolean- whether the hash names an existing unused, unexpired refresh token
Returns
findToken
public abstract OAuth2AuthorizationService.StoredToken findToken(String kind, String tokenHash)consumeToken
public abstract boolean consumeToken(String kind, String tokenHash, long now)now,
and records now as when.Returns
extendToken
public default boolean extendToken(String kind, String tokenHash, long now, long expiresAt)expiresAt, atomically.
Returns false if it is missing, used or expired at now. Custom stores
must implement this before enabling refresh token reuse.touchToken
public abstract void touchToken(String kind, String tokenHash, long now)now, without checking its
previous timestamp. Use pollToken to enforce a polling interval.pollToken
public default boolean pollToken(String kind, String tokenHash, long now, long intervalMillis)now must be one atomic operation, including
across processes sharing a database. Rejected polls do not claim an interval.
Custom stores must implement this before enabling the device grant.Parameters
kindString- Not documented.
tokenHashString- Not documented.
nowlong- Not documented.
intervalMillislong- the minimum time between accepted polls, greater than zero
Returns
decide
public abstract boolean decide(String id, boolean approved, String principalName, Map<String, Object> attributes)OAuth2Authorization.PENDING: makes it
OAuth2Authorization.ACTIVE for principalName, or
OAuth2Authorization.DENIED.Parameters
idString- Not documented.
approvedboolean- Not documented.
principalNameString- Not documented.
attributesMap<String, Object>- what to remember of the user who approved, merged into the grant’s own
Returns
purgeExpired
public abstract int purgeExpired(long now, int limit)limit grants and secrets that expired before now.