使用Redemption配置新的Exchange Online电子邮件配置文件时阻止身份验证提示

时间:2012-03-27 05:15:41

标签: outlook exchange-server mapi office365 outlook-redemption

我遇到一个问题,尝试使用Profman为新配置文件配置Exchange Online邮件服务会导致身份验证提示,并且想知道是否有人之前以编程方式执行了类似操作,以及他们是否能够提供凭据/阻止提示显示?

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)

此外,使用上面的代码,如果我在Outlook中打开之前尝试打开该帐户的RDOStore,或者没有在提示中缓存凭据,则会抛出一个异常,指出.OST不是有效的存储。

到目前为止,我已尝试过:

  • 将凭据添加到RDOSession(如上面的代码示例中所示)
  • 在运行此代码之前手动将凭据添加到Windows凭据管理器(然后仍然会在.Configure()调用时提示输入凭据)。

非常感谢任何提示或想法!

1 个答案:

答案 0 :(得分:0)

Outlook使用凭据缓存,您可以使用RDOSession.Credentials访问它并预填充凭据: http://www.dimastr.com/redemption/rdocredentials.htm 确保指定cpWindowsLogonSession以使其对Outlook可见(而不仅仅是Redemption)。