0
votes

I have an issue where attempting to configure an Exchange Online mail service for a new profile using Profman causes an authentication prompt, and was wondering if anyone had done something similar programmatically before, and whether or not they were able to provide credentials / prevent the prompt from showing?

RDOSession profileSession = RedemptionLoader.new_RDOSession();

string proxy = String.Format("hknprd0204.outlook.com",machineName);
string server = String.Format("hknprd0204.mailbox.outlook.com", machineName);
string userName = "[email protected]";
string password = "P@ssw0rds";

profileSession.Credentials.Add(proxy, userName, password, CredentialPersist: rdoCredentialPersist.cpWindowsLogonSession);
profileSession.Credentials.Add(server, userName, password, CredentialPersist: rdoCredentialPersist.cpWindowsLogonSession);

newProfile = profiles.Add("ExchangeOnline");
newProfile.GlobalProfSect.set_Item((int)Redemption.MAPITags.PR_INTERNET_CONTENT_ID, server);
newProfile.GlobalProfSect.set_Item((int)Redemption.MAPITags.PR_DISPLAY_NAME, userName);

var newService = newProfile.Services.Add("MSEMS", "Microsoft Exchange", false);

ProfMan.PropertyBag properties = (ProfMan.PropertyBag)Activator.CreateInstance(Type.GetTypeFromProgID("ProfMan.PropertyBag"));

properties.Add((int)Redemption.MAPITags.PR_INTERNET_CONTENT_ID, server);
properties.Add((int)Redemption.MAPITags.PR_DISPLAY_NAME, userName);
properties.Add((int)Redemption.MAPITags.PR_PROFILE_HOME_SERVER, server);

properties.Add((int)Redemption.MAPITags.PR_PROFILE_UNRESOLVED_NAME, userName);
properties.Add((int)Redemption.MAPITags.PR_PROFILE_UNRESOLVED_SERVER, server);

properties.Add((int)Redemption.MAPITags.PR_ROH_FLAGS, 47);
properties.Add((int)Redemption.MAPITags.PR_ROH_PROXY_AUTH_SCHEME, Constants.RedemptionPropertyTags.ROHAUTH_BASIC);
properties.Add((int)Redemption.MAPITags.PR_ROH_PROXY_PRINCIPAL_NAME, "msstd:outlook.com");
properties.Add((int)Redemption.MAPITags.PR_ROH_PROXY_SERVER, proxy);
properties.Add((int)Redemption.MAPITags.PR_PROFILE_CONFIG_FLAGS, Constants.RedemptionPropertyTags.CONFIG_OST_CACHE_PRIVATE);

properties.Add((int)Redemption.MAPITags.PR_PROFILE_UI_STATE, 16640);

newService.ProfSect.set_Item((int)Redemption.MAPITags.PR_INTERNET_CONTENT_ID, server);

for (int i = 1; i <= newService.Providers.Count; i++)
{
    ProfMan.IProvider provider = newService.Providers.get_Item(i);
    switch (provider.ResourceType)
    {
        case 33:        //Microsoft Exchange Message Store  todo: constants these
            provider.ProfSect.set_Item((int)Redemption.MAPITags.PR_DISPLAY_NAME, userName);
            provider.ProfSect.set_Item((int)Redemption.MAPITags.PR_INTERNET_CONTENT_ID, server);
            provider.ProfSect.set_Item((int)Redemption.MAPITags.PR_PROFILE_SERVER, server);
            provider.ProfSect.set_Item((int)Redemption.MAPITags.PR_PROFILE_DISPLAYNAME_SET, 1);
            provider.ProfSect.set_Item((int)Redemption.MAPITags.PR_PROFILE_CONFIG_FLAGS, Constants.RedemptionPropertyTags.CONFIG_OST_CACHE_PRIVATE);
            break;
        case 35:        //Exchange Directory Service
            provider.ProfSect.set_Item((int)Redemption.MAPITags.PR_INTERNET_CONTENT_ID, server);
            provider.ProfSect.set_Item((int)Redemption.MAPITags.PR_PROFILE_CONFIG_FLAGS, Constants.RedemptionPropertyTags.CONFIG_OST_CACHE_PRIVATE);
            break;
        case 36:        //Exchange Transport
            provider.ProfSect.set_Item((int)Redemption.MAPITags.PR_INTERNET_CONTENT_ID, server);
            provider.ProfSect.set_Item((int)Redemption.MAPITags.PR_PROFILE_SERVER, server);
            provider.ProfSect.set_Item((int)Redemption.MAPITags.PR_PROFILE_CONFIG_FLAGS, Constants.RedemptionPropertyTags.CONFIG_OST_CACHE_PRIVATE);
            break;
        default:        //0 = MSEMS         This is the provider that is causing the authentication prompt.
            provider.ProfSect.set_Item((int)Redemption.MAPITags.PR_DISPLAY_NAME, userName);
            provider.ProfSect.set_Item((int)Redemption.MAPITags.PR_INTERNET_CONTENT_ID, server);
            provider.ProfSect.set_Item((int)Redemption.MAPITags.PR_PROFILE_HOME_SERVER, server);
            provider.ProfSect.set_Item((int)Redemption.MAPITags.PR_PROFILE_UNRESOLVED_NAME, userName);
            provider.ProfSect.set_Item((int)Redemption.MAPITags.PR_PROFILE_UNRESOLVED_SERVER, server);
            provider.ProfSect.set_Item((int)Redemption.MAPITags.PR_ROH_PROXY_PRINCIPAL_NAME, "msstd:outlook.com");
            provider.ProfSect.set_Item((int)Redemption.MAPITags.PR_ROH_PROXY_SERVER, proxy);
            provider.ProfSect.set_Item((int)Redemption.MAPITags.PR_ROH_PROXY_AUTH_SCHEME, Constants.RedemptionPropertyTags.ROHAUTH_BASIC);
            provider.ProfSect.set_Item((int)Redemption.MAPITags.PR_ROH_FLAGS, 
                    Constants.RedemptionPropertyTags.ROHFLAGS_USE_ROH + 
                    Constants.RedemptionPropertyTags.ROHFLAGS_SSL_ONLY +
                    Constants.RedemptionPropertyTags.ROHFLAGS_MUTUAL_AUTH + 
                    Constants.RedemptionPropertyTags.ROHFLAGS_HTTP_FIRST_ON_SLOW + 
                    Constants.RedemptionPropertyTags.ROHFLAGS_HTTP_FIRST_ON_FAST);
            provider.ProfSect.set_Item((int)Redemption.MAPITags.PR_PROFILE_CONFIG_FLAGS, Constants.RedemptionPropertyTags.CONFIG_OST_CACHE_PRIVATE);
            break;
    }
}

newService.Configure(0, 0, properties);   //Prompts for authentication (and if credentials not cached in resultant prompt, when attempting to access the RDOStore later causes errors)

Additionally, with the above code if I attempt to open the RDOStore for the account prior to opening in Outlook or without caching the credentials in the prompt, an exception is thrown stating that the .OST is not a valid store.

So far, I've tried:

  • adding credentials to an RDOSession (as you can see in the code sample above)
  • adding credentials manually to the windows credential manager prior to running this code (which then still prompts for credentials at the .Configure() call).

Any tips or ideas would be greatly appreciated!

1
Read Stephen Griffin's comments herepcunite

1 Answers

0
votes

Outlook uses credentials cache, you can access it using RDOSession.Credentials and prepopulate the credentials: http://www.dimastr.com/redemption/rdocredentials.htm Make sure you specify cpWindowsLogonSession to make it visible to Outlook (not just Redemption).