Fortunately, there are refresh tokens. A refresh token is given to the client and allows it to get an access token. The refresh token includes a lifetime, typically 15 days, though the user can request more or less.
If you are writing to the API though, you need to know the particulars of managing refresh tokens. Both tokens (access and refresh) are stored locally as part of the Asset. To get another access token, you need to submit a refresh token request along with the current refresh token. You will receive a new access token back along with a new refresh token, valid for as long as the first. All of this is managed in the single getRefreshToken call of the API, so you don't need to sweat over the details. Just make this call whenever you need a new access token and one will be retrieved.
OA2ClientEnvironment ce = OA2ClientEnvironmentUtil.load("/path/to/config.xml", "name-of-config"); OA2MPService service = new OA2MPService(ce); String id = "my:new:id/42"; // Use the webapp to do the authentication. When that is done, you will have // an asset that contains the private key, cert request, access token, refresh token and identifier // So now the scenario is that the client needs to get another certificate. The refresh token // allows this to be done without having the user re-authenticate. Asset2 asset = service.refresh(id); service.getCert(asset); // Now you have the new certs. Access them as per usual, e.g. X509Certificate[] cert = asset.getCertificates();
OA2ClientEnvironment ce = OA2ClientEnvironmentUtil.load("/path/to/config.xml", "name-of-config"); OA2MPService service = new OA2MPService(ce); String id = "my:new:id/42"; // assuming that the user has authenticated by this point UserInfo userInfo = service.getUserInfo(id); userInfo.getName();