001/* 002 * Copyright 2024 Vonage 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package com.vonage.client.auth; 017 018import java.util.Map; 019 020/** 021 * API key and secret in query parameters. 022 * 023 * @since 8.8.0 024 */ 025public class ApiKeyQueryParamsAuthMethod extends AbstractApiKeyQueryParamsAuthMethod { 026 private static final int SORT_KEY = 30; 027 028 private final String apiSecret; 029 030 public ApiKeyQueryParamsAuthMethod(String apiKey, String apiSecret) { 031 super(apiKey); 032 this.apiSecret = apiSecret; 033 } 034 035 /** 036 * Converts this to a {@linkplain BasicAuthMethod}. 037 * 038 * @return A new {@linkplain ApiKeyHeaderAuthMethod} with this object's API key and secret. 039 */ 040 public BasicAuthMethod asBasicHeader() { 041 return new ApiKeyHeaderAuthMethod(apiKey, apiSecret); 042 } 043 044 @Override 045 public Map<String, String> getAuthParams(RequestQueryParams requestParams) { 046 Map<String, String> params = super.getAuthParams(requestParams); 047 params.put("api_secret", apiSecret); 048 return params; 049 } 050 051 @Override 052 public int getSortKey() { 053 return SORT_KEY; 054 } 055}