All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.clouway.oauth2.BearerTokenResponse Maven / Gradle / Ivy

package com.clouway.oauth2;

import com.clouway.friendlyserve.RsJson;
import com.clouway.friendlyserve.RsWrap;
import com.google.common.base.Strings;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

/**
 * BearerTokenResponse is representing the response which is returned by the OAuth Server when token is generated.
 * 

* Bearer Token Usage is described in RFC6750 * * @author Miroslav Genov ([email protected]) */ public class BearerTokenResponse extends RsWrap { public BearerTokenResponse(String accessToken, Long expiresInSeconds, String refreshToken, String encodedIdToken) { super(new RsJson(createToken(accessToken, expiresInSeconds, refreshToken, encodedIdToken) )); } public BearerTokenResponse(String accessToken, Long expiresInSeconds, String refreshToken) { this(accessToken, expiresInSeconds, refreshToken, ""); } private static JsonElement createToken(String accessToken, Long expiresInSeconds, String refreshToken, String encodedIdToken) { JsonObject o = new JsonObject(); o.addProperty("access_token", accessToken); o.addProperty("token_type", "Bearer"); o.addProperty("expires_in", expiresInSeconds); o.addProperty("refresh_token", refreshToken); if (!Strings.isNullOrEmpty(encodedIdToken)) { o.addProperty("id_token", encodedIdToken); } return o; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy