0

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 = "demo@pkstest.onmicrosoft.com";
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!

Henry C
  • 4,781
  • 4
  • 43
  • 83
  • Read Stephen Griffin's comments [here](http://blogs.msdn.com/b/stephen_griffin/archive/2009/08/11/auth-and-check-names.aspx) – pcunite Jun 02 '12 at 16:04

1 Answers1

0

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).

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
  • Hi Dmitry, creating and logging in to an RDOSession seemed to still prompt for credentials: I placed the following code after profiles.Add("MyNewProfile"): RDOSession session = RedemptionLoader.new_RDOSession(); session.Credentials.Add("*.onmicrosoft.com", userName, password, rdoCredentialType.ctGeneric, rdoCredentialPersist.cpWindowsLogonSession); session.Credentials.Add("*.outlook.com", userName, password, rdoCredentialType.ctGeneric, rdoCredentialPersist.cpWindowsLogonSession); And it still prompts for credentials on newService.Configure()... – Henry C Mar 28 '12 at 03:31
  • Looking at the sample on http://www.dimastr.com/redemption/profiles.htm as well, for creating a new profile and adding an exchange server to it, there's a comment saying "'Note: domain logon dialog will always be shown 'if you are not currently logged in to the same domain" - so does this mean Profman.Service.Configure() only works with domain credentials? (and one last thing, when prompted with credentials with my original code above, opening the RDOStore throws MAPI_E_UNCONFIGURED unless i check "save my password" or open with outlook before using it) – Henry C Mar 28 '12 at 03:35