Skip to content

How to extend parameters

bucchi edited this page Mar 16, 2012 · 1 revision

You can extend OAuth2 core parameters as OAuth2 core spec Chapter 8 says without modification to OAuth2 core package.

Here is how to:

  1. create new class which extends BaseTokenType class of core package.
  2. define new TokenType as class variables.
  3. create static block which call addExtension method of BaseTokenType class with thid new class's instance as parameter.
  4. define protected constructor and some other method you want.

done!! Below is the sample:

public class SampleExtendedTokenType extends BaseTokenType {

    public static final String MAC = "mac";

    static {
        addExtension(new SampleExtendedTokenType());
    }

    protected SampleExtendedTokenType() {
    }
}

You can use this extension like this:

SampleExtendedTokenType tokenType = (SampleExtendedTokenType) BaseTokenType.getInstance();

System.out.println(tokenType.MAC);    // this is extended fields
System.out.printlns(tokenType.BEARER); // this is original fields 

Example here is about TokenType extendable parameter class. But there are other extendable parameters class such as:

  • BaseGrantType
  • BaseResponseType
  • BaseErrorCode

You can use those as same way.

Clone this wiki locally