Search code examples
sdkdynamics-crmadfsdynamics-crm-365

SecurityTokenRespone is null


As I stated in the title I have problem with SecurityTokenRespone.

IServiceManagement<IOrganizationService> serviceManagement = ServiceConfigurationFactory.CreateManagement<IOrganizationService>(new Uri("https://SERVICE_URI"));
AuthenticationCredentials authCreds = new AuthenticationCredentials();
authCreds.ClientCredentials.UserName.UserName = userName;
authCreds.ClientCredentials.UserName.Password = password;
AuthenticationCredentials tokenCreds = serviceManagement.Authenticate(authCreds);
SecurityTokenResponse securityToken = tokenCredentials.SecurityTokenResponse;

When I make call to production CRM i get SecurityTokenRespone but when i make call to our test CRM SecurityTokenRespone is null...

Is this because our production CRM have configured ADFS and test CRM doesn't?

If yes, can it be bypassed somehow (our test CRM is in domain that can't be exposed to internet)?

Thank you :)


Solution

  • I assume that on your test CRM you are using just plain AD login without ADFS. If yes then you can't get security token because there isn't one here. To get organization service you go like:

    ClientCredentials clientCreds = new ClientCredentials();
    clientCreds.Windows.ClientCredential.UserName = "username";
    clientCreds.Windows.ClientCredential.Password = "pass";
    clientCreds.Windows.ClientCredential.Domain = "domain";
    IServiceConfiguration<IOrganizationService> orgConfigInfo = ServiceConfigurationFactory.CreateConfiguration<IOrganizationService>(new Uri("http://yourcrmserver/CRO/XRMServices/2011/Organization.svc"));
    OrganizationServiceProxy orgserv = new OrganizationServiceProxy(orgConfigInfo, clientCreds);