Class TokenFactory


  • public class TokenFactory
    extends Object

    Created by Jeff Gaynor
    on 10/19/23 at 1:08 PM

    • Constructor Detail

      • TokenFactory

        public TokenFactory()
    • Method Detail

      • parseRawToken

        protected static void parseRawToken​(String rawToken,
                                            TokenImpl token)
        Parses the raw string from, e.g., a server response and populates a token from that.

        NOTE

        This does no validation on the raw token if it is a JWT, since many times that is not needed and it would create a lot of overhead for no reason. If you need the JWT validated, do it separately.
        Parameters:
        rawToken -
        token -
      • getPayload

        protected static net.sf.json.JSONObject getPayload​(String rawToken)
        Given a raw signed JWT, H.P.S, this will determine if P, the payload, is a JSON object and decode it if so. Otherwise this returns a null.
        Parameters:
        rawToken -
        Returns:
      • createRT

        public static RefreshTokenImpl createRT​(net.sf.json.JSONObject json)
        Recreate the object from its serialized form.
        Parameters:
        json -
        Returns:
      • createAT

        public static AccessTokenImpl createAT​(net.sf.json.JSONObject json)
        Recreate the object from it serialized format. This will fail if the object is not serialized propertly!
        Parameters:
        json -
        Returns:
      • createIDT

        public static IDTokenImpl createIDT​(net.sf.json.JSONObject json)
        In some (legacy) cases, all you have is a parsed payload. This method will create a partial token for this, missing the raw token. Not great but about the best that can be done since the original token and its signature, header, etc. are missing is fake. Alternately, if the argument is just a serialized ID token, this will deserialize it and return it.
        Parameters:
        json -
        Returns: