Deliver expiresAt and providerId for access token

The REST API for OAuth access tokens requires tokens to
have an expiration date and the identifier of the OAuth
provider. This patch adds the missing attributes.

A constant is introduced in OAuthModule to denote the
export name of the provider. This constant is used
to construct the providerId for the representation
of access tokens in the REST API.

Change-Id: I7334949ff18ede75f33eda55a7087655e7b88aa5
Signed-off-by: Michael Ochmann <michael.ochmann@sap.com>
diff --git a/src/main/java/com/googlesource/gerrit/plugins/cfoauth/CFOAuthService.java b/src/main/java/com/googlesource/gerrit/plugins/cfoauth/CFOAuthService.java
index 23968a2..d754307 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/cfoauth/CFOAuthService.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/cfoauth/CFOAuthService.java
@@ -39,6 +39,7 @@
   private static final String NAME = "Cloud Foundry UAA OAuth2";
 
   private final UAAClient uaaClient;
+  private final String providerId;
 
   @Inject
   CFOAuthService(PluginConfigFactory cfgFactory,
@@ -56,6 +57,7 @@
         cfg.getBoolean(InitOAuthConfig.VERIFIY_SIGNATURES, true),
         authConfig.isUserNameToLowerCase(),
         redirectUrl);
+    this.providerId = pluginName + ":" + OAuthModule.EXPORT_ID;
   }
 
   @Override
@@ -131,8 +133,9 @@
     return NAME;
   }
 
-  private static OAuthToken getAsOAuthToken(AccessToken accessToken) {
-    return new OAuthToken(accessToken.getValue(), null, null);
+  private OAuthToken getAsOAuthToken(AccessToken accessToken) {
+    return new OAuthToken(accessToken.getValue(), null, null,
+        accessToken.getExpiresAt() * 1000, providerId);
   }
 
   private static OAuthUserInfo getAsOAuthUserInfo(UserInfo userInfo) {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/cfoauth/HttpModule.java b/src/main/java/com/googlesource/gerrit/plugins/cfoauth/HttpModule.java
index a8948dd..cfaaeb3 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/cfoauth/HttpModule.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/cfoauth/HttpModule.java
@@ -39,7 +39,7 @@
     PluginConfig cfg = cfgFactory.getFromGerritConfig(pluginName);
     if (cfg.getString(InitOAuthConfig.CLIENT_ID) != null) {
       bind(OAuthServiceProvider.class)
-       .annotatedWith(Exports.named(pluginName))
+       .annotatedWith(Exports.named(OAuthModule.EXPORT_ID))
        .to(CFOAuthService.class);
     }
   }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/cfoauth/OAuthModule.java b/src/main/java/com/googlesource/gerrit/plugins/cfoauth/OAuthModule.java
index b1dcc8c..96735bd 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/cfoauth/OAuthModule.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/cfoauth/OAuthModule.java
@@ -24,6 +24,8 @@
 
 class OAuthModule extends AbstractModule {
 
+  static final String EXPORT_ID = "cfoauth";
+
   private final PluginConfigFactory cfgFactory;
   private final String pluginName;
 
@@ -39,7 +41,7 @@
     PluginConfig cfg = cfgFactory.getFromGerritConfig(pluginName);
     if (cfg.getString(InitOAuthConfig.CLIENT_ID) != null) {
       bind(OAuthLoginProvider.class)
-       .annotatedWith(Exports.named(pluginName))
+       .annotatedWith(Exports.named(EXPORT_ID))
        .to(CFOAuthService.class);
     }
   }