@Test public void testIssueAccessToken() throws Exception { doReturn(EXPECTED_RESULT).when(httpClient).post( any(Uri.class), anyMapOf(String.class, String.class), anyMapOf(String.class, String.class), any(ResponseDataParser.class)); LineApiResponse<IssueAccessTokenResult> actualResult = target.issueAccessToken( CHANNEL_ID, "testRequestToken", PKCE_CODE, "testRedirectUri"); assertSame(EXPECTED_RESULT, actualResult); Map<String, String> expectedPostData = new HashMap<>(7); expectedPostData.put("grant_type", "authorization_code"); expectedPostData.put("code", "testRequestToken"); expectedPostData.put("redirect_uri", "testRedirectUri"); expectedPostData.put("client_id", CHANNEL_ID); expectedPostData.put("code_verifier", PKCE_CODE.getVerifier()); expectedPostData.put("id_token_key_type", IdTokenKeyType.JWK.name()); expectedPostData.put("client_version", "LINE SDK Android v" + BuildConfig.VERSION_NAME); verify(httpClient, times(1)).post( eq(Uri.parse(API_BASE_URL + "/oauth2/v2.1/token")), eq(Collections.emptyMap()), eq(expectedPostData), responseParserCaptor.capture()); verifyIssueAccessTokenResultParser(responseParserCaptor.getValue()); }
@NonNull public LineApiResponse<IssueAccessTokenResult> issueAccessToken( @NonNull String channelId, @NonNull String requestToken, @NonNull PKCECode pkceCode, @NonNull String redirectUri) { final Uri uri = buildUri(apiBaseUrl, BASE_PATH_OAUTH_V21_API, "token"); final Map<String, String> postData = buildParams( "grant_type", "authorization_code", "code", requestToken, "redirect_uri", redirectUri, "client_id", channelId, "code_verifier", pkceCode.getVerifier(), "id_token_key_type", IdTokenKeyType.JWK.name(), "client_version", "LINE SDK Android v" + BuildConfig.VERSION_NAME ); return httpClient.post( uri, emptyMap() , postData, ISSUE_ACCESS_TOKEN_RESULT_PARSER); }
LineAuthenticationApiClient { @NonNull public LineApiResponse<IssueAccessTokenResult> issueAccessToken( @NonNull String channelId, @NonNull String requestToken, @NonNull PKCECode pkceCode, @NonNull String redirectUri) { final Uri uri = buildUri(apiBaseUrl, BASE_PATH_OAUTH_V21_API, "token"); final Map<String, String> postData = buildParams( "grant_type", "authorization_code", "code", requestToken, "redirect_uri", redirectUri, "client_id", channelId, "code_verifier", pkceCode.getVerifier(), "id_token_key_type", IdTokenKeyType.JWK.name(), "client_version", "LINE SDK Android v" + BuildConfig.VERSION_NAME ); return httpClient.post( uri, emptyMap() , postData, ISSUE_ACCESS_TOKEN_RESULT_PARSER); } }
LineAuthenticationApiClient { @NonNull public LineApiResponse<IssueAccessTokenResult> issueAccessToken( @NonNull String channelId, @NonNull String requestToken, @NonNull PKCECode pkceCode, @NonNull String redirectUri) { final Uri uri = buildUri(apiBaseUrl, BASE_PATH_OAUTH_V21_API, "token"); final Map<String, String> postData = buildParams( "grant_type", "authorization_code", "code", requestToken, "redirect_uri", redirectUri, "client_id", channelId, "code_verifier", pkceCode.getVerifier(), "id_token_key_type", IdTokenKeyType.JWK.name(), "client_version", "LINE SDK Android v" + BuildConfig.VERSION_NAME ); return httpClient.post( uri, emptyMap() , postData, ISSUE_ACCESS_TOKEN_RESULT_PARSER); } LineAuthenticationApiClient(@NonNull final Context applicationContext,
                                       @NonNull final Uri openidDiscoveryDocumentUrl,
                                       @NonNull final Uri apiBaseUrl); @VisibleForTesting  LineAuthenticationApiClient(
            @NonNull final Uri openidDiscoveryDocumentUrl,
            @NonNull final Uri apiBaseUrl,
            @NonNull final ChannelServiceHttpClient httpClient); }
LineAuthenticationApiClient { @NonNull public LineApiResponse<IssueAccessTokenResult> issueAccessToken( @NonNull String channelId, @NonNull String requestToken, @NonNull PKCECode pkceCode, @NonNull String redirectUri) { final Uri uri = buildUri(apiBaseUrl, BASE_PATH_OAUTH_V21_API, "token"); final Map<String, String> postData = buildParams( "grant_type", "authorization_code", "code", requestToken, "redirect_uri", redirectUri, "client_id", channelId, "code_verifier", pkceCode.getVerifier(), "id_token_key_type", IdTokenKeyType.JWK.name(), "client_version", "LINE SDK Android v" + BuildConfig.VERSION_NAME ); return httpClient.post( uri, emptyMap() , postData, ISSUE_ACCESS_TOKEN_RESULT_PARSER); } LineAuthenticationApiClient(@NonNull final Context applicationContext,
                                       @NonNull final Uri openidDiscoveryDocumentUrl,
                                       @NonNull final Uri apiBaseUrl); @VisibleForTesting  LineAuthenticationApiClient(
            @NonNull final Uri openidDiscoveryDocumentUrl,
            @NonNull final Uri apiBaseUrl,
            @NonNull final ChannelServiceHttpClient httpClient); @NonNull LineApiResponse<IssueAccessTokenResult> issueAccessToken(
            @NonNull String channelId,
            @NonNull String requestToken,
            @NonNull PKCECode pkceCode,
            @NonNull String redirectUri); @NonNull LineApiResponse<AccessTokenVerificationResult> verifyAccessToken(
            @NonNull InternalAccessToken accessToken); @NonNull LineApiResponse<RefreshTokenResult> refreshToken(
            @NonNull String channelId, @NonNull InternalAccessToken accessToken); @NonNull LineApiResponse<?> revokeAccessToken(@NonNull String channelId,
                                                @NonNull InternalAccessToken accessToken); @NonNull LineApiResponse<?> revokeRefreshToken(@NonNull String channelId,
                                                 @NonNull InternalAccessToken accessToken); @NonNull LineApiResponse<OpenIdDiscoveryDocument> getOpenIdDiscoveryDocument(); @NonNull LineApiResponse<JWKSet> getJWKSet(); }
LineAuthenticationApiClient { @NonNull public LineApiResponse<IssueAccessTokenResult> issueAccessToken( @NonNull String channelId, @NonNull String requestToken, @NonNull PKCECode pkceCode, @NonNull String redirectUri) { final Uri uri = buildUri(apiBaseUrl, BASE_PATH_OAUTH_V21_API, "token"); final Map<String, String> postData = buildParams( "grant_type", "authorization_code", "code", requestToken, "redirect_uri", redirectUri, "client_id", channelId, "code_verifier", pkceCode.getVerifier(), "id_token_key_type", IdTokenKeyType.JWK.name(), "client_version", "LINE SDK Android v" + BuildConfig.VERSION_NAME ); return httpClient.post( uri, emptyMap() , postData, ISSUE_ACCESS_TOKEN_RESULT_PARSER); } LineAuthenticationApiClient(@NonNull final Context applicationContext,
                                       @NonNull final Uri openidDiscoveryDocumentUrl,
                                       @NonNull final Uri apiBaseUrl); @VisibleForTesting  LineAuthenticationApiClient(
            @NonNull final Uri openidDiscoveryDocumentUrl,
            @NonNull final Uri apiBaseUrl,
            @NonNull final ChannelServiceHttpClient httpClient); @NonNull LineApiResponse<IssueAccessTokenResult> issueAccessToken(
            @NonNull String channelId,
            @NonNull String requestToken,
            @NonNull PKCECode pkceCode,
            @NonNull String redirectUri); @NonNull LineApiResponse<AccessTokenVerificationResult> verifyAccessToken(
            @NonNull InternalAccessToken accessToken); @NonNull LineApiResponse<RefreshTokenResult> refreshToken(
            @NonNull String channelId, @NonNull InternalAccessToken accessToken); @NonNull LineApiResponse<?> revokeAccessToken(@NonNull String channelId,
                                                @NonNull InternalAccessToken accessToken); @NonNull LineApiResponse<?> revokeRefreshToken(@NonNull String channelId,
                                                 @NonNull InternalAccessToken accessToken); @NonNull LineApiResponse<OpenIdDiscoveryDocument> getOpenIdDiscoveryDocument(); @NonNull LineApiResponse<JWKSet> getJWKSet();  }