Java Code Examples for com.linecorp.linesdk.LineApiResponse#getResponseData()
The following examples show how to use
com.linecorp.linesdk.LineApiResponse#getResponseData() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LineAuthenticationController.java From line-sdk-android with Apache License 2.0 | 6 votes |
private void validateIdToken(final LineIdToken idToken, final String userId) { final LineApiResponse<OpenIdDiscoveryDocument> response = authApiClient.getOpenIdDiscoveryDocument(); if (!response.isSuccess()) { throw new RuntimeException("Failed to get OpenId Discovery Document. " + " Response Code: " + response.getResponseCode() + " Error Data: " + response.getErrorData()); } final OpenIdDiscoveryDocument openIdDiscoveryDoc = response.getResponseData(); final IdTokenValidator idTokenValidator = new Builder() .idToken(idToken) .expectedIssuer(openIdDiscoveryDoc.getIssuer()) .expectedUserId(userId) .expectedChannelId(config.getChannelId()) .expectedNonce(authenticationStatus.getOpenIdNonce()) .build(); idTokenValidator.validate(); }
Example 2
Source File: OpenIdSigningKeyResolver.java From line-sdk-android with Apache License 2.0 | 6 votes |
private Key resolveSigningKey(final JwsHeader header) { final LineApiResponse<JWKSet> response = apiClient.getJWKSet(); if (!response.isSuccess()) { Log.e(TAG, "failed to get LINE JSON Web Key Set [JWK] document."); return null; } final JWKSet jwkSet = response.getResponseData(); final String keyId = header.getKeyId(); final JWK jwk = jwkSet.getJWK(keyId); if (jwk == null) { Log.e(TAG, "failed to find Key by Id: " + keyId); return null; } final String algorithm = header.getAlgorithm(); final SignatureAlgorithm alg = SignatureAlgorithm.forName(algorithm); if (alg.isEllipticCurve()) { return generateECPublicKey(jwk); } throw new SecurityException("Unsupported signature algorithm '" + algorithm + '\''); }
Example 3
Source File: LineAuthenticationApiClient.java From line-sdk-android with Apache License 2.0 | 6 votes |
@NonNull public LineApiResponse<JWKSet> getJWKSet() { final LineApiResponse<OpenIdDiscoveryDocument> discoveryDocResponse = getOpenIdDiscoveryDocument(); if (!discoveryDocResponse.isSuccess()) { return LineApiResponse.createAsError(discoveryDocResponse.getResponseCode(), discoveryDocResponse.getErrorData()); } final OpenIdDiscoveryDocument openIdDiscoveryDoc = discoveryDocResponse.getResponseData(); final Uri jwksUri = Uri.parse(openIdDiscoveryDoc.getJwksUri()); final LineApiResponse<JWKSet> jwkSetResponse = httpClient.get(jwksUri, emptyMap(), emptyMap(), JWK_SET_PARSER); if (!jwkSetResponse.isSuccess()) { Log.e(TAG, "getJWKSet failed: " + jwkSetResponse); } return jwkSetResponse; }
Example 4
Source File: LineApiClientImplTest.java From line-sdk-android with Apache License 2.0 | 6 votes |
@Test public void testGetCurrentAccessToken() { LineApiResponse<LineAccessToken> response; LineAccessToken actualAccessToken; // the cached access token is null. response = target.getCurrentAccessToken(); assertFalse(response.isSuccess()); // the cached access token is not null. accessTokenCache.saveAccessToken(ACCESS_TOKEN); response = target.getCurrentAccessToken(); assertTrue(response.isSuccess()); actualAccessToken = response.getResponseData(); assertNotNull(actualAccessToken); assertEquals(ACCESS_TOKEN.getAccessToken(), actualAccessToken.getTokenString()); assertEquals(ACCESS_TOKEN.getExpiresInMillis(), actualAccessToken.getExpiresInMillis()); assertEquals(ACCESS_TOKEN.getIssuedClientTimeMillis(), actualAccessToken.getIssuedClientTimeMillis()); }
Example 5
Source File: GetTargetUserTask.java From line-sdk-android with Apache License 2.0 | 5 votes |
private void getAllFriends() { String nextPageToken = ""; while (nextPageToken != null) { LineApiResponse<GetFriendsResponse> response = lineApiClient.getFriends(FriendSortField.RELATION, nextPageToken, true); if (!response.isSuccess()) { publishProgress(Collections.emptyList()); return; } GetFriendsResponse getFriendsResponse = response.getResponseData(); publishProgress(convertFriendsToTargetUsers(getFriendsResponse.getFriends())); nextPageToken = getFriendsResponse.getNextPageRequestToken(); } }
Example 6
Source File: GetTargetUserTask.java From line-sdk-android with Apache License 2.0 | 5 votes |
private void getAllGroups() { String nextPageToken = ""; while (nextPageToken != null) { LineApiResponse<GetGroupsResponse> response = lineApiClient.getGroups(nextPageToken, true); if (!response.isSuccess()) { publishProgress(Collections.emptyList()); return; } GetGroupsResponse getGroupsResponse = response.getResponseData(); publishProgress(convertGroupsToTargetUsers(getGroupsResponse.getGroups())); nextPageToken = getGroupsResponse.getNextPageRequestToken(); } }
Example 7
Source File: LineApiClientImpl.java From line-sdk-android with Apache License 2.0 | 5 votes |
@NonNull private LineApiResponse<LineCredential> verifyToken(@NonNull InternalAccessToken accessToken) { LineApiResponse<AccessTokenVerificationResult> response = oauthApiClient.verifyAccessToken(accessToken); if (!response.isSuccess()) { return LineApiResponse.createAsError( response.getResponseCode(), response.getErrorData()); } AccessTokenVerificationResult verificationResult = response.getResponseData(); long verifiedClientTimeMillis = System.currentTimeMillis(); try { accessTokenCache.saveAccessToken( new InternalAccessToken( accessToken.getAccessToken(), verificationResult.getExpiresInMillis(), verifiedClientTimeMillis, accessToken.getRefreshToken())); } catch(Exception exception) { return LineApiResponse.createAsError( LineApiResponseCode.INTERNAL_ERROR, new LineApiError("save access token fail:" + exception.getMessage()) ); } return LineApiResponse.createAsSuccess( new LineCredential( new LineAccessToken( accessToken.getAccessToken(), verificationResult.getExpiresInMillis(), verifiedClientTimeMillis), verificationResult.getScopes())); }
Example 8
Source File: LineAuthenticationController.java From line-sdk-android with Apache License 2.0 | 4 votes |
@Override protected LineLoginResult doInBackground(@Nullable BrowserAuthenticationApi.Result... params) { BrowserAuthenticationApi.Result authResult = params[0]; String requestToken = authResult.getRequestToken(); PKCECode pkceCode = authenticationStatus.getPKCECode(); String sentRedirectUri = authenticationStatus.getSentRedirectUri(); if (TextUtils.isEmpty(requestToken) || pkceCode == null || TextUtils.isEmpty(sentRedirectUri)) { return LineLoginResult.internalError("Requested data is missing."); } // Acquire access token LineApiResponse<IssueAccessTokenResult> accessTokenResponse = authApiClient.issueAccessToken( config.getChannelId(), requestToken, pkceCode, sentRedirectUri); if (!accessTokenResponse.isSuccess()) { return LineLoginResult.error(accessTokenResponse); } IssueAccessTokenResult issueAccessTokenResult = accessTokenResponse.getResponseData(); InternalAccessToken accessToken = issueAccessTokenResult.getAccessToken(); List<Scope> scopes = issueAccessTokenResult.getScopes(); LineProfile lineProfile = null; String userId = null; if (scopes.contains(Scope.PROFILE)) { // Acquire account information LineApiResponse<LineProfile> profileResponse = talkApiClient.getProfile(accessToken); if (!profileResponse.isSuccess()) { return LineLoginResult.error(profileResponse); } lineProfile = profileResponse.getResponseData(); userId = lineProfile.getUserId(); } // Cache the acquired access token accessTokenCache.saveAccessToken(accessToken); final LineIdToken idToken = issueAccessTokenResult.getIdToken(); if (idToken != null) { try { validateIdToken(idToken, userId); } catch (final Exception e) { return LineLoginResult.internalError(e.getMessage()); } } return new LineLoginResult.Builder() .nonce(authenticationStatus.getOpenIdNonce()) .lineProfile(lineProfile) .lineIdToken(idToken) .friendshipStatusChanged(authResult.getFriendshipStatusChanged()) .lineCredential(new LineCredential( new LineAccessToken( accessToken.getAccessToken(), accessToken.getExpiresInMillis(), accessToken.getIssuedClientTimeMillis()), scopes )) .build(); }