Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.

public final class OAuth2Parameters

  1. Object
  2. OAuth2Parameters
The small pieces of text an OAuth2 exchange is made of: a form, a query, a list of scopes, a random value, a PKCE challenge. Written here once because both sides of the exchange – the client that signs in elsewhere and the server that issues tokens – read and write the same ones.

Methods

public static String encode(String value)value as application/x-www-form-urlencoded writes it: every byte of its UTF-8 that is not a letter, a digit or one of -._~ as %XX.
public static String decode(String value)The reverse of encode, with + read as a space; null when value is not a well-formed encoding.
public static Map<String, String> parse(String form)The fields of a form or a query, in order.
public static List<String> values(String form, String name)Every value the field name has in a form or a query, in order: for a parameter that may be sent more than once, as resource may.
public static String format(Map<String, ?> fields)fields as a form body or a query, without a leading ?.
public static String append(String uri, Map<String, ?> fields)uri with fields added to its query.
public static Set<String> scopes(String list)The scopes of a space-separated list, in order, each once.
public static String scopes(Collection<String> scopes)scopes as one space-separated value.
public static String random(int bytes)A value nobody can guess: bytes bytes from the system’s generator, written in the URL-safe alphabet.
public static String sha256(String value)The SHA-256 of value in the URL-safe alphabet: the S256 challenge of a PKCE verifier, and what a secret token is stored and looked up by.
public static boolean equalsConstantTime(String a, String b)Whether two values are equal, in time that does not depend on where they differ.
public static byte[] utf8(String value)The bytes of value in UTF-8.
public static String string(byte[] bytes)The text of bytes, read as UTF-8.

Inherited methods

Method details

encode

public static String encode(String value)
value as application/x-www-form-urlencoded writes it: every byte of its UTF-8 that is not a letter, a digit or one of -._~ as %XX.

decode

public static String decode(String value)
The reverse of encode, with + read as a space; null when value is not a well-formed encoding.

parse

public static Map<String, String> parse(String form)
The fields of a form or a query, in order. A field that appears twice keeps its first value; one that does not decode is left out.

values

public static List<String> values(String form, String name)
Every value the field name has in a form or a query, in order: for a parameter that may be sent more than once, as resource may. A value that does not decode is left out.

format

public static String format(Map<String, ?> fields)
fields as a form body or a query, without a leading ?. A null value is left out.

append

public static String append(String uri, Map<String, ?> fields)
uri with fields added to its query.

scopes

public static Set<String> scopes(String list)
The scopes of a space-separated list, in order, each once.

scopes

public static String scopes(Collection<String> scopes)
scopes as one space-separated value.

random

public static String random(int bytes)
A value nobody can guess: bytes bytes from the system’s generator, written in the URL-safe alphabet. 32 bytes is 256 bits.

sha256

public static String sha256(String value)
The SHA-256 of value in the URL-safe alphabet: the S256 challenge of a PKCE verifier, and what a secret token is stored and looked up by.

equalsConstantTime

public static boolean equalsConstantTime(String a, String b)
Whether two values are equal, in time that does not depend on where they differ.

utf8

public static byte[] utf8(String value)
The bytes of value in UTF-8.

string

public static String string(byte[] bytes)
The text of bytes, read as UTF-8.