public void RegisterAndEnrollAccount(AuthenticationResult authenticationResult, Endpoint endPoint = null) { try { if (endPoint != null) { Endpoint = endPoint; } else { throw new Exception(Lib.Intune.Constants.Enrollment.ERRORENDPOINTNULL); } if (authenticationResult != null && Endpoint != null) { var upn = authenticationResult?.UserInfo.DisplayableId; var aadId = authenticationResult?.UserInfo?.UniqueId; var tenantId = authenticationResult?.TenantId; _loggingService.LogInformation(typeof(EnrollmentService), $"{Lib.Intune.Constants.Enrollment.ENROLLMENTLOGTAG} UPN {upn}\n TenantId: {tenantId}\n AadId: {aadId} \n"); _enrollmentManager.RegisterAccountForMAM(upn, aadId, tenantId); } else { throw new Exception(Lib.Intune.Constants.Enrollment.ERRORNULL); } } catch (Exception ex) { var status = new Status { Error = ex.Message, DidSucceed = false, StatusCode = StatusCode.InternalError }; _loggingService.LogError(typeof(EnrollmentService), ex, ex.Message); EnrollmentRequestStatus(status, _authenticationResult); } }
/// <summary> /// Authenticates the user. /// </summary> /// <param name="behavior">The ADAL prompt behavior.</param> /// <returns>The authentication result.</returns> public async Task <AuthenticationResult> Authenticate(PromptBehavior behavior) { // Check initial authentication values. if (_clientID.Equals(_placeholderClientID) || _redirectURI.Equals(_placeholderRedirectURI)) { Toast.MakeText(Android.App.Application.Context, "Please update the authentication values for your application.", ToastLength.Long).Show(); Log.Info(_logTagAuth, "Authentication cancelled. Authentication values need to be updated with user provided values." + " Client ID = " + _clientID + " Redirect URI = " + _redirectURI); return(null); } if (!Uri.IsWellFormedUriString(_redirectURI, UriKind.RelativeOrAbsolute)) { Toast.MakeText(Android.App.Application.Context, "Please correct the redirect URI for your application.", ToastLength.Long).Show(); Log.Info(_logTagAuth, "Authentication cancelled. Redirect URI needs to be corrected with a well-formed value." + " Redirect URI = " + _redirectURI); return(null); } AuthenticationResult result = null; // Register the callback to capture ADAL logs. LoggerCallbackHandler.LogCallback = ADALLog; LoggerCallbackHandler.PiiLoggingEnabled = true; // Attempt to sign the user in silently. result = await SignInSilent(_resourceID, null); // If the user cannot be signed in silently, prompt the user to manually sign in. if (result == null) { result = await SignInWithPrompt(new PlatformParameters((Activity)Forms.Context, false, behavior)); } // If auth was successful, cache the values and log the success. if (result != null && result.AccessToken != null) { _cachedUPN = result.UserInfo.DisplayableId; _cachedAADID = result.UserInfo.UniqueId; Log.Info(_logTagAuth, "Authentication succeeded. UPN = " + _cachedUPN); // Register the account for MAM // See: https://docs.microsoft.com/en-us/intune/app-sdk-android#account-authentication // This app requires ADAL authentication prior to MAM enrollment so we delay the registration // until after the sign in flow. IMAMEnrollmentManager mgr = MAMComponents.Get <IMAMEnrollmentManager>(); mgr.RegisterAccountForMAM(_cachedUPN, _cachedAADID, result.TenantId); } return(result); }
/// <summary> /// Attempts to register the account for MAM using the given access token before moving on /// to the main view /// </summary> /// <param name="result"> the AuthenticationResult containing a valid access token</param> public void OnSignedIn(AuthenticationResult result) { string upn = result.UserInfo.DisplayableId; string aadId = result.UserInfo.UniqueId; string tenantId = result.TenantId; // Register the account for MAM // See: https://docs.microsoft.com/en-us/intune/app-sdk-android#account-authentication // This app requires ADAL authentication prior to MAM enrollment so we delay the registration // until after the sign in flow. IMAMEnrollmentManager mgr = MAMComponents.Get <IMAMEnrollmentManager>(); mgr.RegisterAccountForMAM(upn, aadId, tenantId); //Must be run on the UI thread because it is modifying the UI RunOnUiThread(OpenMainview); }
public async Task RegisterAndEnrollAccountAsync(Endpoint endPoint) { try { if (endPoint != null) { Endpoint = endPoint; mAMWEAuthCallback.CurrentEndpoint = endPoint; var token = await _authenticatorEndpointService.AcquireTokenSilentAsync(endPoint); if (token != null) { _loggingService.LogInformation(typeof(EnrollmentService), $"{Lib.Intune.Constants.Enrollment.ENROLLMENTLOGTAG} UPN {token.UserInfo.DisplayableId}\n TenantId: {token.UserInfo.UniqueId}\n AadId: {token.TenantId} \n"); InTuneLoggingService.Instance.AddMessage(new LoggingMessage { LogDate = DateTime.Now, Message = "Starting Register and Enrollment", Module = SDKModule.Enrollment }); _enrollmentManager.RegisterAccountForMAM(token.UserInfo.DisplayableId, token.UserInfo.UniqueId, token.TenantId); } else { throw new Exception(Lib.Intune.Constants.Enrollment.ERRORNULL); } } else { throw new Exception(Lib.Intune.Constants.Enrollment.ERRORENDPOINTNULL); } } catch (Exception ex) { var status = new Status { Error = ex.Message, DidSucceed = false, StatusCode = StatusCode.InternalError }; _loggingService.LogError(typeof(EnrollmentService), ex, ex.Message); EnrollmentRequestStatus(status); } }