Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public final class OAuth2AuthorizationServer
- Object
- OAuth2AuthorizationServer
AuthorizationServerConfigurer,
which is also where every rule these endpoints apply is described.Fields
public static final String AUTH_TIME = "cn1.security.oauth2.authTime" | Session attribute holding the last completed credential check, in epoch seconds. |
public static final String AUTH_METHODS = "cn1.security.oauth2.authMethods" | Session attribute holding how the last completed credential check was made: RFC 8176 method names separated by spaces, such as pwd otp mfa. |
Constructors
Methods
Inherited methods
Field details
AUTH_TIME
public static final String AUTH_TIME = "cn1.security.oauth2.authTime"AUTH_METHODS
public static final String AUTH_METHODS = "cn1.security.oauth2.authMethods"pwd otp mfa.
A grant made in the session carries them as its amr attribute, and the
ID token as its amr claim, so a resource server can tell a passkey
sign-in from a password one. A token customizer copies the attribute
into an access token that needs it.Constructor details
OAuth2AuthorizationServer
public OAuth2AuthorizationServer(AuthorizationServerSettings settings, String fixedIssuer, String defaultAudience, RegisteredClientRepository clients, OAuth2AuthorizationService authorizations, JwkSource keys, JwtEncoder encoder, PasswordEncoder secrets, OAuth2TokenCustomizer customizer, OidcUserInfoMapper userInfo, RateLimiter verificationLimiter, int verificationAttempts, long verificationWindowSeconds, Clock clock)Parameters
settingsAuthorizationServerSettings- Not documented.
fixedIssuerString- the issuer, or null to read it off each request: a development profile only
defaultAudienceString- the
audof an access token whose request named noresource; null for the issuer clientsRegisteredClientRepository- Not documented.
authorizationsOAuth2AuthorizationService- Not documented.
keysJwkSource- Not documented.
encoderJwtEncoder- Not documented.
secretsPasswordEncoder- what client secrets were encoded with; null when no client has one
customizerOAuth2TokenCustomizer- Not documented.
userInfoOidcUserInfoMapper- Not documented.
verificationLimiterRateLimiter- what bounds wrong user codes; null to count in this process
verificationAttemptsint- how many user codes one user may try in a window, when this process counts
verificationWindowSecondslong- the length of that window
clockClock- Not documented.
Method details
getSettings
public AuthorizationServerSettings getSettings()handle
public HttpServer.Response handle(HttpServer.Request request, String path)Parameters
requestHttpServer.Request- Not documented.
pathString- the request’s path
Returns
path is none of themisUserEndpoint
public boolean isUserEndpoint(String path)path is an endpoint a user must be signed in for: the
authorization endpoint or the device verification page.authorize
public HttpServer.Response authorize(HttpServer.Request request, Authentication authentication)Answers the authorization endpoint for a browser whose user is
authentication.
The client and the redirect address are checked before anything else, and a request that fails either is answered here, with a 400: an error is sent to a redirect address only once that address is known to be the client’s own.
InsufficientAuthenticationException: when nobody is signed in and the request is a browser’s, so that the chain sends it to sign in and back
Parameters
requestHttpServer.Request- Not documented.
authenticationAuthentication- who is signed in; null for nobody
authMethods
public static String authMethods(Authentication authentication, boolean secondFactor)amr values for a completed sign-in, space separated:
hwk for a passkey (and user plus mfa when the authenticator
verified the user), otherwise pwd, with otp and mfa added when a
second factor was passed. A kind of sign-in it does not know – a
remember-me cookie, say – answers null and nothing is recorded.Parameters
authenticationAuthentication- Not documented.
secondFactorboolean- whether the sign-in passed a second factor
deviceVerification
public HttpServer.Response deviceVerification(HttpServer.Request request, Authentication authentication, String csrfParameter, String csrfToken)Answers the device verification page for the signed-in user
authentication: the form that takes a user code, the question that
follows a right one, and the answer to that question.
The chain’s CSRF protection covers the two posts; the token to put in the forms is passed in.
InsufficientAuthenticationException: when nobody is signed in, so that the chain sends the browser to sign in and back
Parameters
requestHttpServer.Request- Not documented.
authenticationAuthentication- who is signed in; null for nobody
csrfParameterString- the name of the CSRF form field, or null
csrfTokenString- its value
deviceVerification
public HttpServer.Response deviceVerification(HttpServer.Request request, Authentication authentication, String csrfParameter, String csrfHeader, String csrfToken)deviceVerification(HttpServer.Request, Authentication, String, String),
told the header a CSRF token may come back in as well.
The endpoint has two forms, and the request chooses. A browser gets the
pages. A request that asks for JSON – its Accept names
application/json and not text/html, or its body is
application/json – gets the same three steps as data, so that an
application that signed the user in itself can put its own screen in
front of them:
GET:{"csrf": {"headerName", "parameterName", "token"}}, the token a post must carry when the chain protects against CSRF.POST {"user_code": "..."}: the question, as{"user_code", "client_id", "client_name", "scope", "principal", "ticket"}.POST {"user_code": "...", "ticket": "...", "decision": "approve"}or"deny":{"status": "approved"}or{"status": "denied"}.
Nothing is relaxed for it. The user must be signed in – a request that
is not is answered 401 login_required rather than sent to a login
page – the chain’s CSRF protection covers both posts, each try at a
code is counted, and an answer counts only with the ticket this server
put in that session with the question, once. A code that is not valid
is 400 invalid_grant, an answer without its ticket 400
invalid_request, and too many tries 429 slow_down.
Parameters
requestHttpServer.Request- Not documented.
authenticationAuthentication- Not documented.
csrfParameterString- Not documented.
csrfHeaderString- the name of the header a CSRF token may be sent in, or null
csrfTokenString- Not documented.