public override void OnMAMCreate() { // Register the notification receivers IMAMNotificationReceiverRegistry registry = MAMComponents.Get <IMAMNotificationReceiverRegistry>(); registry.RegisterReceiver(new MAMNotificationReceiver(), MAMNotificationType.MamEnrollmentResult); base.OnMAMCreate(); }
/// <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); }
public EnrollmentService(ILoggingService loggingService) { _loggingService = loggingService; _enrollmentManager = MAMComponents.Get <IMAMEnrollmentManager>(); _notificationRegistery = MAMComponents.Get <IMAMNotificationReceiverRegistry>(); _authenticationResult = null; _registerError = null; Endpoint = null; RegisteredAccounts = new List <string>(); _notificationRegistery.RegisterReceiver(this, MAMNotificationType.MamEnrollmentResult); _notificationRegistery.RegisterReceiver(this, MAMNotificationType.RefreshPolicy); _enrollmentManager.RegisterAuthenticationCallback(new MAMWEAuthCallback()); }
/// <summary> /// Attempt to get a token from the cache without prompting the user for authentication. /// </summary> /// <returns> A token on success, null otherwise </returns> public async void UpdateAccessTokenForMAM() { if (string.IsNullOrWhiteSpace(_cachedResourceID)) { Log.Warn(_logTagAuth, "Resource ID is not set, cannot update access token for MAM."); return; } string token = await GetAccessTokenForMAM(_cachedAADID, _cachedResourceID); if (!string.IsNullOrWhiteSpace(token)) { IMAMEnrollmentManager mgr = MAMComponents.Get <IMAMEnrollmentManager>(); mgr.UpdateToken(_cachedUPN, _cachedAADID, _cachedResourceID, token); } }
/// <summary> /// Signs the user out of the application and unenrolls from MAM. /// </summary> public void SignOut() { // Clear the app's token cache so the user will be prompted to sign in again. authContext.TokenCache.Clear(); string user = User; if (user != null) { // Remove the user's MAM policy from the app IMAMEnrollmentManager mgr = MAMComponents.Get <IMAMEnrollmentManager>(); mgr.UnregisterAccountForMAM(user); } Toast.MakeText(Android.App.Application.Context, Resource.String.auth_out_success, ToastLength.Short).Show(); }
public override void OnMAMCreate() { // as per Intune SDK doc, callback registration must be done here. // https://docs.microsoft.com/en-us/mem/intune/developer/app-sdk-android IMAMEnrollmentManager mgr = MAMComponents.Get <IMAMEnrollmentManager>(); mgr.RegisterAuthenticationCallback(new MAMWEAuthCallback()); // Register the notification receivers to receive MAM notifications. // Along with other, this will receive notification that the device has been enrolled. IMAMNotificationReceiverRegistry registry = MAMComponents.Get <IMAMNotificationReceiverRegistry>(); registry.RegisterReceiver(new EnrollmentNotificationReceiver(), MAMNotificationType.MamEnrollmentResult); base.OnMAMCreate(); }
/// <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); }
/// <summary> /// Perform registration with MAM /// </summary> /// <param name="exProtection"></param> /// <returns></returns> private async Task DoMAMRegister(IntuneAppProtectionPolicyRequiredException exProtection) { // reset the registered event IntuneSampleApp.MAMRegsiteredEvent.Reset(); // Invoke compliance API on a different thread await Task.Run(() => { IMAMComplianceManager mgr = MAMComponents.Get <IMAMComplianceManager>(); mgr.RemediateCompliance(exProtection.Upn, exProtection.AccountUserId, exProtection.TenantId, exProtection.AuthorityUrl, false); }).ConfigureAwait(false); // wait till the registration completes // Note: This is a sample app for MSAL.NET. Scenarios such as what if enrollment fails or user chooses not to enroll will be as // per the business requirements of the app and not considered in the sample app. IntuneSampleApp.MAMRegsiteredEvent.WaitOne(); }
/// <summary> /// Signs the user out of the application and unenrolls from MAM. /// </summary> /// <param name="listener"></param> public void SignOut(IAuthListener listener) { // Clear the app's token cache so the user will be prompted to sign in again. authContext.TokenCache.Clear(); string user = User; if (user != null) { // Remove the user's MAM policy from the app IMAMEnrollmentManager mgr = MAMComponents.Get <IMAMEnrollmentManager>(); mgr.UnregisterAccountForMAM(user); } isAuthenticated = false; listener.OnSignedOut(); }
public override View OnMAMCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.Inflate(Resource.Layout.fragment_about, container, false); // Needed to make the links active TextView body1 = view.FindViewById <TextView>(Resource.Id.about_nav_body_1); body1.MovementMethod = LinkMovementMethod.Instance; TextView body2 = view.FindViewById <TextView>(Resource.Id.about_nav_body_2); body2.MovementMethod = LinkMovementMethod.Instance; TextView footer = view.FindViewById <TextView>(Resource.Id.about_nav_footer); footer.MovementMethod = LinkMovementMethod.Instance; TextView configText = view.FindViewById <TextView>(Resource.Id.about_nav_config_text); // Get and show the targeted application configuration IMAMAppConfigManager configManager = MAMComponents.Get <IMAMAppConfigManager>(); IMAMAppConfig appConfig = configManager.GetAppConfig(AuthManager.User); if (appConfig == null) { configText.Text = GetString(Resource.String.err_unset); } else { StringBuilder builder = new StringBuilder(); IList <IDictionary <string, string> > appConfigData = appConfig.FullData; foreach (IDictionary <string, string> dictionary in appConfigData) { foreach (KeyValuePair <string, string> kvp in dictionary) { builder.AppendLine(string.Format("Key = {0}, Value = {1}", kvp.Key, kvp.Value)); } } configText.Text = GetString(Resource.String.about_nav_config_text, builder.ToString()); } return(view); }
/// <summary> /// Signs the user out of the application and unenrolls from MAM. /// </summary> public async void SignOut() { // Clear the app's token cache so the user will be prompted to sign in again. var currentAccounts = await PCA.GetAccountsAsync(); if (currentAccounts.Count() > 0) { await PCA.RemoveAsync(currentAccounts.FirstOrDefault()); } string user = User; if (user != null) { // Remove the user's MAM policy from the app IMAMEnrollmentManager mgr = MAMComponents.Get <IMAMEnrollmentManager>(); mgr.UnregisterAccountForMAM(user); } Toast.MakeText(Android.App.Application.Context, Resource.String.auth_out_success, ToastLength.Short).Show(); }
public override void OnMAMCreate() { // Register the MAMAuthenticationCallback as soon as possible. // This will handle acquiring the necessary access token for MAM. IMAMEnrollmentManager mgr = MAMComponents.Get <IMAMEnrollmentManager>(); mgr.RegisterAuthenticationCallback(new MAMWEAuthCallback()); // Register the notification receivers to receive MAM notifications. // Applications can receive notifications from the MAM SDK at any time. // More information can be found here: https://docs.microsoft.com/en-us/intune/app-sdk-android#register-for-notifications-from-the-sdk IMAMNotificationReceiverRegistry registry = MAMComponents.Get <IMAMNotificationReceiverRegistry>(); foreach (MAMNotificationType notification in MAMNotificationType.Values()) { registry.RegisterReceiver(new ToastNotificationReceiver(this), notification); } registry.RegisterReceiver(new EnrollmentNotificationReceiver(this), MAMNotificationType.MamEnrollmentResult); registry.RegisterReceiver(new WipeNotificationReceiver(this), MAMNotificationType.WipeUserData); base.OnMAMCreate(); }
/// <summary> /// Gets the current MAM app config for the application. /// </summary> /// <returns>The current MAM app config.</returns> public string GetCurrentAppConfig() { IMAMAppConfigManager configManager = MAMComponents.Get <IMAMAppConfigManager>(); IMAMAppConfig appConfig = configManager.GetAppConfig(Authenticator.User); if (appConfig != null) { StringBuilder builder = new StringBuilder(); IList <IDictionary <string, string> > appConfigData = appConfig.FullData; foreach (IDictionary <string, string> dictionary in appConfigData) { foreach (KeyValuePair <string, string> kvp in dictionary) { builder.AppendLine(string.Format("Key = {0}, Value = {1}", kvp.Key, kvp.Value)); } } return(Application.Context.GetString(Resource.String.about_nav_config_text, builder.ToString())); } return(Application.Context.GetString(Resource.String.about_nav_config_text_missing)); }
/// <summary> /// Signs the user out of the application and unenrolls from MAM. /// </summary> /// <param name="listener"></param> public async void SignOut(IAuthListener listener) { // Clear the app's token cache so the user will be prompted to sign in again. var currentAccounts = await PCA.GetAccountsAsync(); if (currentAccounts.Count() > 0) { await PCA.RemoveAsync(currentAccounts.FirstOrDefault()); } string user = User; if (user != null) { // Remove the user's MAM policy from the app IMAMEnrollmentManager mgr = MAMComponents.Get <IMAMEnrollmentManager>(); mgr.UnregisterAccountForMAM(user); } isAuthenticated = false; listener.OnSignedOut(); }
public ConfigManagerService(ILoggingService loggingService) { _loggingService = loggingService; _configManager = MAMComponents.Get <IMAMAppConfigManager>(); }
public void UtilMAMService() { IMAMAppConfigManager _configManager; // private IMAMEnrollmentManager _enrolledMgr; IMAMUserInfo _userInfo; try { //_enrolledMgr = MAMComponents.Get<IMAMEnrollmentManager>(); _userInfo = MAMComponents.Get <IMAMUserInfo>(); // if (_enrolledMgr.GetRegisteredAccountStatus(_userInfo.PrimaryUser) == MAMEnrollmentManagerResult.EnrollmentSucceeded) // { _configManager = MAMComponents.Get <IMAMAppConfigManager>(); _userInfo = MAMComponents.Get <IMAMUserInfo>(); string identity = _userInfo.PrimaryUser; Utils.PrintDeep($"---------------------------------------------------------- va a buscar la configuracion de: {identity} "); //identity = "*****@*****.**"; var stringValues = new List <Dictionary <string, string> >(); var dict = new Dictionary <string, string>(); try { var items = _configManager.GetAppConfig(identity); if (items != null) { foreach (var item in items.FullData) { //var dict = new Dictionary<string, string>(); foreach (var key in item.Keys) { var value = item[key]; dict.Add(key, value); } stringValues.Add(dict); } } } catch (Exception ex) { return; } var data = Mobile.configData; if (dict.ContainsKey(Mobile.ID_FTP_HOST)) { dict.TryGetValue(Mobile.ID_FTP_HOST, out data.ftpDownload_Host); } else { return; } // Convert parameters to string and regenerate the certificate if (dict.ContainsKey(Mobile.ID_FTP_USER)) { dict.TryGetValue(Mobile.ID_FTP_USER, out data.ftpDownload_User); } if (dict.ContainsKey(Mobile.ID_FTP_PORT)) { dict.TryGetValue(Mobile.ID_FTP_PORT, out string Port); data.ftpDownload_Port = int.Parse(Port); } if (dict.ContainsKey(Mobile.ID_FTP_PATH)) { dict.TryGetValue(Mobile.ID_FTP_PATH, out data.ftpDownload_Path); } if (dict.ContainsKey(Mobile.ID_FTP_PASS)) { dict.TryGetValue(Mobile.ID_FTP_PASS, out data.ftpDownload_Pass); } data.HasIntune = true; string certificate = string.Empty; if (dict.TryGetValue(Mobile.ID_CERTIFICATE, out certificate)) { data.StoreCertificate(data.CreateCertificate(certificate)); //save the certificate in keychain data.GenerateCertFromStore(); //data.GenerateCert(certificate); } } catch (Exception e) { return; } }