Search in sources :

Example 56 with Credentials

use of okhttp3.Credentials in project FortniteAPI by Xilixir.

the class Example method main.

public static void main(String[] args) {
    Configuration login = new Configuration("login", Credentials.class);
    Credentials credentials = login.read();
    FortniteAPI api = new FortniteAPI(credentials);
    try {
        api.authenticate();
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        EpicLookup lookup = api.getUserInfo("bad.player");
        Friend[] friends = api.getFriendListData(lookup.getId());
        for (Friend friend : friends) {
            if (friend.getStatus() == Status.PENDING && friend.getDirection() == Direction.INBOUND) {
                System.out.println("attempting to delete friend: " + new Gson().toJson(friend));
                api.deleteFriendRequest(lookup.getId(), friend.getAccountId());
            }
        }
        System.out.println(new Gson().toJson(friends));
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : Configuration(com.xilixir.fortniteapi.v2.Configuration) Friend(com.xilixir.fortniteapi.v2.Epic.Friends.Friend) Gson(com.google.gson.Gson) IOException(java.io.IOException) FortniteAPI(com.xilixir.fortniteapi.v2.FortniteAPI) Credentials(com.xilixir.fortniteapi.v2.Credentials) EpicLookup(com.xilixir.fortniteapi.v2.Epic.EpicLookup)

Example 57 with Credentials

use of okhttp3.Credentials in project photon-model by vmware.

the class AzureCostStatsService method getAuth.

/**
 * Gets the credentials (enrollment number & API key) required to call the Azure API for
 * requesting data.
 */
private void getAuth(Context context, Stages next) {
    logInfo(() -> String.format("Starting azure ea cost stats collection for endpoint %s ", context.computeHostDesc.endpointLink));
    URI authUri = UriUtils.extendUri(getInventoryServiceUri(), context.endpointState.authCredentialsLink);
    Consumer<Operation> onSuccess = (op) -> {
        context.auth = op.getBody(AuthCredentialsServiceState.class);
        context.stage = next;
        handleRequest(context);
    };
    AdapterUtils.getServiceState(this, authUri, onSuccess, getFailureConsumer(context));
}
Also used : AzureCostConstants(com.vmware.photon.controller.model.adapters.azure.constants.AzureCostConstants) AzureStatsNormalizer(com.vmware.photon.controller.model.adapters.azure.utils.AzureStatsNormalizer) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) Arrays(java.util.Arrays) DateTimeZone(org.joda.time.DateTimeZone) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) QueryTask(com.vmware.xenon.services.common.QueryTask) ServiceDocument(com.vmware.xenon.common.ServiceDocument) AzureUriPaths(com.vmware.photon.controller.model.adapters.azure.AzureUriPaths) StringUtils(org.apache.commons.lang3.StringUtils) ComputeType(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType) EndpointAllocationTaskService(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService) SingleResourceStatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState) Utils(com.vmware.xenon.common.Utils) BufferedSink(okio.BufferedSink) Map(java.util.Map) AzureService(com.vmware.photon.controller.model.adapters.azure.model.cost.AzureService) URI(java.net.URI) AzureSubscriptionsEnumerationRequest(com.vmware.photon.controller.model.adapters.azure.ea.enumeration.AzureSubscriptionsEnumerationService.AzureSubscriptionsEnumerationRequest) Builder(com.vmware.xenon.services.common.QueryTask.Builder) Path(java.nio.file.Path) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) Interceptor(okhttp3.Interceptor) ComputeStatsResponse(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse) AzureDetailedBillHandler(com.vmware.photon.controller.model.adapters.azure.ea.utils.AzureDetailedBillHandler) Request(okhttp3.Request) ComputeStatsRequest(com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest) StatelessService(com.vmware.xenon.common.StatelessService) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) OldEaSummarizedBillElement(com.vmware.photon.controller.model.adapters.azure.model.cost.OldEaSummarizedBillElement) TaskManager(com.vmware.photon.controller.model.adapters.util.TaskManager) Set(java.util.Set) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) AzureSubscriptionsEnumerationService(com.vmware.photon.controller.model.adapters.azure.ea.enumeration.AzureSubscriptionsEnumerationService) AzureCostHelper(com.vmware.photon.controller.model.adapters.azure.ea.utils.AzureCostHelper) List(java.util.List) Stream(java.util.stream.Stream) UriUtils(com.vmware.xenon.common.UriUtils) Entry(java.util.Map.Entry) QueryOption(com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption) INTERNAL_REQUEST_TIMEOUT_SECONDS(com.vmware.photon.controller.model.adapters.azure.constants.AzureCostConstants.INTERNAL_REQUEST_TIMEOUT_SECONDS) ResourceMetrics(com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics) SingleResourceTaskCollectionStage(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceTaskCollectionStage) Okio(okio.Okio) QueryByPages(com.vmware.photon.controller.model.query.QueryUtils.QueryByPages) OperationContext(com.vmware.xenon.common.OperationContext) AtomicDouble(com.google.common.util.concurrent.AtomicDouble) HashMap(java.util.HashMap) Function(java.util.function.Function) AzureResource(com.vmware.photon.controller.model.adapters.azure.model.cost.AzureResource) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) EndpointConfigRequest(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest) Query(com.vmware.xenon.services.common.QueryTask.Query) CollectionUtils(org.apache.commons.collections.CollectionUtils) EaBillLinkElement(com.vmware.photon.controller.model.adapters.azure.model.cost.EaBillLinkElement) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) AUTO_DISCOVERED_ENTITY(com.vmware.photon.controller.model.constants.PhotonModelConstants.AUTO_DISCOVERED_ENTITY) EaBillLinks(com.vmware.photon.controller.model.adapters.azure.model.cost.EaBillLinks) BiConsumer(java.util.function.BiConsumer) Response(okhttp3.Response) EndpointType(com.vmware.photon.controller.model.constants.PhotonModelConstants.EndpointType) Call(okhttp3.Call) Callback(okhttp3.Callback) AzureSubscription(com.vmware.photon.controller.model.adapters.azure.model.cost.AzureSubscription) ComputeStats(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats) ExecutorService(java.util.concurrent.ExecutorService) OldApi(com.vmware.photon.controller.model.adapters.azure.model.cost.OldApi) AdapterUtils(com.vmware.photon.controller.model.adapters.util.AdapterUtils) ServiceErrorResponse(com.vmware.xenon.common.ServiceErrorResponse) Files(java.nio.file.Files) Operation(com.vmware.xenon.common.Operation) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) TypeName(com.vmware.xenon.common.ServiceDocumentDescription.TypeName) ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) File(java.io.File) QueryTop(com.vmware.photon.controller.model.query.QueryUtils.QueryTop) BillParsingStatus(com.vmware.photon.controller.model.adapters.azure.model.cost.BillParsingStatus) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) LocalDate(org.joda.time.LocalDate) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) OkHttpClient(okhttp3.OkHttpClient) Paths(java.nio.file.Paths) ClusterUtil(com.vmware.photon.controller.model.util.ClusterUtil) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) PhotonModelConstants(com.vmware.photon.controller.model.constants.PhotonModelConstants) ServiceDocumentDescription(com.vmware.xenon.common.ServiceDocumentDescription) Comparator(java.util.Comparator) QuerySpecification(com.vmware.xenon.services.common.QueryTask.QuerySpecification) OperationJoin(com.vmware.xenon.common.OperationJoin) Operation(com.vmware.xenon.common.Operation) URI(java.net.URI)

Example 58 with Credentials

use of okhttp3.Credentials in project mbed-cloud-sdk-java by ARMmbed.

the class HttpBasicAuth method intercept.

@Override
public Response intercept(Chain chain) throws IOException {
    Request request = chain.request();
    // If the request already have an authorization (eg. Basic auth), do nothing
    if (request.header("Authorization") == null) {
        String credentials = Credentials.basic(username, password);
        request = request.newBuilder().addHeader("Authorization", credentials).build();
    }
    return chain.proceed(request);
}
Also used : Request(okhttp3.Request)

Example 59 with Credentials

use of okhttp3.Credentials in project mbed-cloud-sdk-java by ARMmbed.

the class HttpBasicAuth method intercept.

@Override
public Response intercept(Chain chain) throws IOException {
    Request request = chain.request();
    // If the request already have an authorization (eg. Basic auth), do nothing
    if (request.header("Authorization") == null) {
        String credentials = Credentials.basic(username, password);
        request = request.newBuilder().addHeader("Authorization", credentials).build();
    }
    return chain.proceed(request);
}
Also used : Request(okhttp3.Request)

Example 60 with Credentials

use of okhttp3.Credentials in project dhis2-android-sdk by dhis2.

the class BasicAuthenticatorShould method return_test_and_user_when_server_take_request.

@Test
public void return_test_and_user_when_server_take_request() throws IOException, InterruptedException {
    AuthenticatedUserModel authenticatedUserModel = AuthenticatedUserModel.builder().user("test_user").credentials(base64("test_user", "test_password")).build();
    when(authenticatedUserStore.query()).thenReturn(Arrays.asList(authenticatedUserModel));
    okHttpClient.newCall(new Request.Builder().url(mockWebServer.url("/api/me/")).build()).execute();
    RecordedRequest recordedRequest = mockWebServer.takeRequest();
    assertThat(recordedRequest.getHeader("Authorization")).isEqualTo(basic("test_user", "test_password"));
}
Also used : AuthenticatedUserModel(org.hisp.dhis.android.core.user.AuthenticatedUserModel) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Test(org.junit.Test)

Aggregations

Request (okhttp3.Request)39 Response (okhttp3.Response)29 OkHttpClient (okhttp3.OkHttpClient)22 IOException (java.io.IOException)20 Test (org.junit.Test)16 HttpUrl (okhttp3.HttpUrl)10 RequestBody (okhttp3.RequestBody)9 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)9 ResponseBody (okhttp3.ResponseBody)8 NonNull (androidx.annotation.NonNull)7 MockResponse (okhttp3.mockwebserver.MockResponse)7 BasicAuthenticator (com.burgstaller.okhttp.basic.BasicAuthenticator)6 CachingAuthenticator (com.burgstaller.okhttp.digest.CachingAuthenticator)6 Credentials (com.burgstaller.okhttp.digest.Credentials)6 DigestAuthenticator (com.burgstaller.okhttp.digest.DigestAuthenticator)6 Observable (rx.Observable)6 AuthenticationCacheInterceptor (com.burgstaller.okhttp.AuthenticationCacheInterceptor)5 CachingAuthenticatorDecorator (com.burgstaller.okhttp.CachingAuthenticatorDecorator)5 PokemonGo (com.pokegoapi.api.PokemonGo)5 PtcCredentialProvider (com.pokegoapi.auth.PtcCredentialProvider)5