-
Notifications
You must be signed in to change notification settings - Fork 20
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:
- create new class which extends BaseTokenType class of core package.
- define new TokenType as class variables.
- create static block which call addExtension method of BaseTokenType class with thid new class's instance as parameter.
- 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.