Search in sources :

Example 6 with ApiStartEvent

use of com.microsoft.identity.common.internal.telemetry.events.ApiStartEvent in project microsoft-authentication-library-common-for-android by AzureAD.

the class LocalMSALController method getAccounts.

@Override
@WorkerThread
public List<ICacheRecord> getAccounts(@NonNull final CommandParameters parameters) {
    Telemetry.emit(new ApiStartEvent().putProperties(parameters).putApiId(TelemetryEventStrings.Api.LOCAL_GET_ACCOUNTS));
    @SuppressWarnings(WarningType.unchecked_warning) final List<ICacheRecord> accountsInCache = parameters.getOAuth2TokenCache().getAccountsWithAggregatedAccountData(// * wildcard
    null, parameters.getClientId());
    Telemetry.emit(new ApiEndEvent().putApiId(TelemetryEventStrings.Api.LOCAL_GET_ACCOUNTS).put(TelemetryEventStrings.Key.ACCOUNTS_NUMBER, Integer.toString(accountsInCache.size())).put(TelemetryEventStrings.Key.IS_SUCCESSFUL, TelemetryEventStrings.Value.TRUE));
    return accountsInCache;
}
Also used : ICacheRecord(com.microsoft.identity.common.internal.cache.ICacheRecord) ApiEndEvent(com.microsoft.identity.common.internal.telemetry.events.ApiEndEvent) ApiStartEvent(com.microsoft.identity.common.internal.telemetry.events.ApiStartEvent) WorkerThread(androidx.annotation.WorkerThread)

Example 7 with ApiStartEvent

use of com.microsoft.identity.common.internal.telemetry.events.ApiStartEvent in project microsoft-authentication-library-common-for-android by AzureAD.

the class LocalMSALController method deviceCodeFlowAuthRequest.

// Suppressing rawtype warnings due to the generic types AuthorizationResult and OAuth2Strategy
@SuppressWarnings(WarningType.rawtype_warning)
@Override
public AuthorizationResult deviceCodeFlowAuthRequest(final DeviceCodeFlowCommandParameters parameters) throws ServiceException, ClientException, IOException {
    // Logging start of method
    final String methodName = ":deviceCodeFlowAuthRequest";
    Logger.verbose(TAG + methodName, "Device Code Flow: Authorizing user code...");
    // Default scopes here
    final Set<String> mergedScopes = addDefaultScopes(parameters);
    final DeviceCodeFlowCommandParameters parametersWithScopes = parameters.toBuilder().scopes(mergedScopes).build();
    logParameters(TAG, parametersWithScopes);
    // Start telemetry with LOCAL_DEVICE_CODE_FLOW_ACQUIRE_URL_AND_CODE
    Telemetry.emit(new ApiStartEvent().putProperties(parametersWithScopes).putApiId(TelemetryEventStrings.Api.LOCAL_DEVICE_CODE_FLOW_ACQUIRE_URL_AND_CODE));
    final Authority.KnownAuthorityResult authorityResult = Authority.getKnownAuthorityResult(parametersWithScopes.getAuthority());
    // If not known throw resulting exception
    if (!authorityResult.getKnown()) {
        Telemetry.emit(new ApiEndEvent().putException(authorityResult.getClientException()).putApiId(TelemetryEventStrings.Api.LOCAL_DEVICE_CODE_FLOW_ACQUIRE_URL_AND_CODE));
        throw authorityResult.getClientException();
    }
    final AuthorizationResult authorizationResult;
    try {
        // Create OAuth2Strategy using commandParameters and strategyParameters
        final OAuth2StrategyParameters strategyParameters = new OAuth2StrategyParameters();
        strategyParameters.setContext(parametersWithScopes.getAndroidApplicationContext());
        final OAuth2Strategy oAuth2Strategy = parametersWithScopes.getAuthority().createOAuth2Strategy(strategyParameters);
        // DCF protocol step 1: Get user code
        // Populate global authorization request
        mAuthorizationRequest = getAuthorizationRequest(oAuth2Strategy, parametersWithScopes);
        // Call method defined in oAuth2Strategy to request authorization
        authorizationResult = oAuth2Strategy.getDeviceCode((MicrosoftStsAuthorizationRequest) mAuthorizationRequest);
        validateServiceResult(authorizationResult);
    } catch (Exception error) {
        Telemetry.emit(new ApiEndEvent().putException(error).putApiId(TelemetryEventStrings.Api.LOCAL_DEVICE_CODE_FLOW_ACQUIRE_URL_AND_CODE));
        throw error;
    }
    Logger.verbose(TAG + methodName, "Device Code Flow authorization step finished...");
    logResult(TAG, authorizationResult);
    // End telemetry with LOCAL_DEVICE_CODE_FLOW_ACQUIRE_URL_AND_CODE
    Telemetry.emit(new ApiEndEvent().putApiId(TelemetryEventStrings.Api.LOCAL_DEVICE_CODE_FLOW_ACQUIRE_URL_AND_CODE));
    return authorizationResult;
}
Also used : MicrosoftStsAuthorizationRequest(com.microsoft.identity.common.internal.providers.microsoft.microsoftsts.MicrosoftStsAuthorizationRequest) ApiEndEvent(com.microsoft.identity.common.internal.telemetry.events.ApiEndEvent) Authority(com.microsoft.identity.common.internal.authorities.Authority) DeviceCodeFlowCommandParameters(com.microsoft.identity.common.internal.commands.parameters.DeviceCodeFlowCommandParameters) ApiStartEvent(com.microsoft.identity.common.internal.telemetry.events.ApiStartEvent) OAuth2StrategyParameters(com.microsoft.identity.common.internal.providers.oauth2.OAuth2StrategyParameters) OAuth2Strategy(com.microsoft.identity.common.internal.providers.oauth2.OAuth2Strategy) AuthorizationResult(com.microsoft.identity.common.internal.providers.oauth2.AuthorizationResult) ServiceException(com.microsoft.identity.common.exception.ServiceException) ClientException(com.microsoft.identity.common.exception.ClientException) IOException(java.io.IOException) ArgumentException(com.microsoft.identity.common.exception.ArgumentException) ExecutionException(java.util.concurrent.ExecutionException)

Example 8 with ApiStartEvent

use of com.microsoft.identity.common.internal.telemetry.events.ApiStartEvent in project microsoft-authentication-library-common-for-android by AzureAD.

the class TelemetryTest method testITelemetryDefaultObserver.

@Test
public void testITelemetryDefaultObserver() {
    Telemetry.getInstance().addObserver(new ITelemetryDefaultObserver() {

        @Override
        public void onReceived(List<Map<String, String>> telemetryData) {
            final Map<String, String> mapWithExpectedInfo = telemetryData.get(0);
            final String apiId = mapWithExpectedInfo.get(TelemetryEventStrings.Key.API_ID);
            final String authorityType = mapWithExpectedInfo.get(TelemetryEventStrings.Key.AUTHORITY_TYPE);
            Assert.assertEquals("100", apiId);
            Assert.assertEquals("AAD", authorityType);
        }
    });
    Telemetry.emit(new ApiStartEvent().putApiId("100").putAuthorityType("AAD"));
    Telemetry.getInstance().flush();
}
Also used : ITelemetryDefaultObserver(com.microsoft.identity.common.internal.telemetry.observers.ITelemetryDefaultObserver) ApiStartEvent(com.microsoft.identity.common.internal.telemetry.events.ApiStartEvent) Map(java.util.Map) Test(org.junit.Test)

Example 9 with ApiStartEvent

use of com.microsoft.identity.common.internal.telemetry.events.ApiStartEvent in project microsoft-authentication-library-common-for-android by AzureAD.

the class TelemetryTest method testITelemetryAggregatedObserver.

@Test
public void testITelemetryAggregatedObserver() {
    Telemetry.getInstance().addObserver(new ITelemetryAggregatedObserver() {

        @Override
        public void onReceived(Map<String, String> telemetryData) {
            final String apiId = telemetryData.get(TelemetryEventStrings.Key.API_ID);
            Assert.assertEquals("100", apiId);
        }
    });
    Telemetry.emit(new ApiStartEvent().putApiId("100"));
    Telemetry.getInstance().flush();
}
Also used : ApiStartEvent(com.microsoft.identity.common.internal.telemetry.events.ApiStartEvent) ITelemetryAggregatedObserver(com.microsoft.identity.common.internal.telemetry.observers.ITelemetryAggregatedObserver) Test(org.junit.Test)

Aggregations

ApiStartEvent (com.microsoft.identity.common.internal.telemetry.events.ApiStartEvent)9 ApiEndEvent (com.microsoft.identity.common.internal.telemetry.events.ApiEndEvent)7 ICacheRecord (com.microsoft.identity.common.internal.cache.ICacheRecord)4 OAuth2Strategy (com.microsoft.identity.common.internal.providers.oauth2.OAuth2Strategy)4 OAuth2StrategyParameters (com.microsoft.identity.common.internal.providers.oauth2.OAuth2StrategyParameters)4 AcquireTokenResult (com.microsoft.identity.common.internal.result.AcquireTokenResult)4 ClientException (com.microsoft.identity.common.exception.ClientException)3 LocalAuthenticationResult (com.microsoft.identity.common.internal.result.LocalAuthenticationResult)3 WorkerThread (androidx.annotation.WorkerThread)2 ArgumentException (com.microsoft.identity.common.exception.ArgumentException)2 ServiceException (com.microsoft.identity.common.exception.ServiceException)2 Authority (com.microsoft.identity.common.internal.authorities.Authority)2 AuthorizationResult (com.microsoft.identity.common.internal.providers.oauth2.AuthorizationResult)2 TokenResult (com.microsoft.identity.common.internal.providers.oauth2.TokenResult)2 IOException (java.io.IOException)2 ExecutionException (java.util.concurrent.ExecutionException)2 Test (org.junit.Test)2 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 BaseException (com.microsoft.identity.common.exception.BaseException)1