token provider

Aurélien Pupier edited this page Oct 26, 2017 · 4 revisions

JBossTools OpenShift now provides (as of 4.5.1.Final) a new module that allows external services to integrate with and get a token for API access.

Here is a general description of the functionality and how to use it.


The module simply export an extension point that allows to get a token for API access. The module will stored a single account with the access and refresh tokens and their expiry dates. If the module gets called when there is no account stored, a login against will be processed and returned tokens will be saved. If an account is stored in the database, then tokens are verified and returned if they are still valid. If not, a refresh is performed if the refresh token is still valid. Otherwise, a login is performed again to get new tokens. As there is currently support for a single account, if you want to switch to another account, you need to reset the database. This is possible through the Eclipse preferences, the node is JBoss Tools ->


Loose coupling

In this mode, you don't need extra import or dependencies in our code but you just need to retrieve the extension point and cast it to java.util.function.Function<IResource, String> Javadoc

An example code how to the retrieve the extension point is given here:

private Function<IResource, String> getProvider() {
	IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor("");
	for(IConfigurationElement element : elements) {
		try {
			return (Function<IResource, String>) element.createExecutableExtension("class");
		} catch (CoreException e) {
			Fabric8AnalysisLSActivator.getDefault().getLog().log(new Status(IStatus.ERROR, Fabric8AnalysisLSActivator.getDefault().getBundle().getSymbolicName(), e.getLocalizedMessage(), e));
	return null;

then on the returned object, call the apply function to get a token:

String token = provider.apply(null);

Please note that the parameter of the Function object is here for context passing but is currently not used so passing null is fine.

Strong coupling

The main difference is that the type of the extension point is not a generic Function object but rather a instance. The main difference is that you can now call the getToken method instead of the Function apply method:

String token = provider.getToken(null);

In order to use the, your bundle must import the package or have a dependency on bundle.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.