protected Builder(ClientId clientId) { this.clientId = clientId.getClientId(); this.clientSecret = clientId.getClientSecret(); }
protected Builder(ClientId clientId) { this.clientId = clientId.getClientId(); this.clientSecret = clientId.getClientSecret(); }
@Test public void fromResource() throws IOException { ClientId clientId = ClientId.fromResource(ClientIdTest.class, "/client_secret.json"); assertEquals(CLIENT_ID, clientId.getClientId()); assertEquals(CLIENT_SECRET, clientId.getClientSecret()); }
@Test public void fromJson_installedNoSecret() throws IOException { GenericJson json = writeClientIdJson("installed", CLIENT_ID, null); ClientId clientId = ClientId.fromJson(json); assertEquals(CLIENT_ID, clientId.getClientId()); assertNull(clientId.getClientSecret()); }
tokenData.put("client_id", clientId.getClientId()); tokenData.put("client_secret", clientId.getClientSecret()); tokenData.put("redirect_uri", resolvedCallbackUri); .setClientId(clientId.getClientId()) .setClientSecret(clientId.getClientSecret()) .setRefreshToken(refreshToken)
@Test public void fromJson_installed() throws IOException { GenericJson json = writeClientIdJson("installed", CLIENT_ID, CLIENT_SECRET); ClientId clientId = ClientId.fromJson(json); assertEquals(CLIENT_ID, clientId.getClientId()); assertEquals(CLIENT_SECRET, clientId.getClientSecret()); }
@Test public void fromJson_web() throws IOException { GenericJson json = writeClientIdJson("web", CLIENT_ID, CLIENT_SECRET); ClientId clientId = ClientId.fromJson(json); assertEquals(CLIENT_ID, clientId.getClientId()); assertEquals(CLIENT_SECRET, clientId.getClientSecret()); }
tokenData.put("client_id", clientId.getClientId()); tokenData.put("client_secret", clientId.getClientSecret()); tokenData.put("redirect_uri", resolvedCallbackUri); .setClientId(clientId.getClientId()) .setClientSecret(clientId.getClientSecret()) .setRefreshToken(refreshToken)
@Test public void fromStream() throws IOException { String text = "{" + "\"web\": {" + "\"client_id\" : \"" + CLIENT_ID + "\"," + "\"client_secret\" : \"" + CLIENT_SECRET + "\"" + "}" + "}"; InputStream stream = TestUtils.stringToInputStream(text); ClientId clientId = ClientId.fromStream(stream); assertEquals(CLIENT_ID, clientId.getClientId()); assertEquals(CLIENT_SECRET, clientId.getClientSecret()); }
tokenJson, "refresh_token", TOKEN_STORE_ERROR); UserCredentials credentials = UserCredentials.newBuilder() .setClientId(clientId.getClientId()) .setClientSecret(clientId.getClientSecret()) .setRefreshToken(refreshToken)
tokenJson, "refresh_token", TOKEN_STORE_ERROR); UserCredentials credentials = UserCredentials.newBuilder() .setClientId(clientId.getClientId()) .setClientSecret(clientId.getClientSecret()) .setRefreshToken(refreshToken)
@Test public void constructor_nullClientSecret() { ClientId clientId = ClientId.newBuilder() .setClientId(CLIENT_ID) .build(); assertEquals(CLIENT_ID, clientId.getClientId()); assertNull(clientId.getClientSecret()); }
@Test public void constructor() { ClientId clientId = ClientId.newBuilder() .setClientId(CLIENT_ID) .setClientSecret(CLIENT_SECRET) .build(); assertEquals(CLIENT_ID, clientId.getClientId()); assertEquals(CLIENT_SECRET, clientId.getClientSecret()); }
/** * Return an URL that performs the authorization consent prompt web UI. * * @param userId Application's identifier for the end user. * @param state State that is passed on to the OAuth2 callback URI after the consent. * @param baseUri The URI to resolve the OAuth2 callback URI relative to. * @return The URL that can be navigated or redirected to. */ public URL getAuthorizationUrl(String userId, String state, URI baseUri) { URI resolvedCallbackUri = getCallbackUri(baseUri); String scopesString = Joiner.on(' ').join(scopes); GenericUrl url = new GenericUrl(userAuthUri); url.put("response_type", "code"); url.put("client_id", clientId.getClientId()); url.put("redirect_uri", resolvedCallbackUri); url.put("scope", scopesString); if (state != null) { url.put("state", state); } url.put("access_type", "offline"); url.put("approval_prompt", "force"); if (userId != null) { url.put("login_hint", userId); } url.put("include_granted_scopes", true); return url.toURL(); }
/** * Return an URL that performs the authorization consent prompt web UI. * * @param userId Application's identifier for the end user. * @param state State that is passed on to the OAuth2 callback URI after the consent. * @param baseUri The URI to resolve the OAuth2 callback URI relative to. * @return The URL that can be navigated or redirected to. */ public URL getAuthorizationUrl(String userId, String state, URI baseUri) { URI resolvedCallbackUri = getCallbackUri(baseUri); String scopesString = Joiner.on(' ').join(scopes); GenericUrl url = new GenericUrl(userAuthUri); url.put("response_type", "code"); url.put("client_id", clientId.getClientId()); url.put("redirect_uri", resolvedCallbackUri); url.put("scope", scopesString); if (state != null) { url.put("state", state); } url.put("access_type", "offline"); url.put("approval_prompt", "force"); if (userId != null) { url.put("login_hint", userId); } url.put("include_granted_scopes", true); return url.toURL(); }