Answered by:
Urgent : Security in authentication to retrieve data from MS CRM 2011

Question
-
Hello All,
Before retrieving data from MS CRM 2011, we need to authenticate. So is there any security mechanism for authentication like security token, access key etc.
Please help.
- Edited by JaiHariHar Monday, August 26, 2013 10:43 AM
Monday, August 26, 2013 10:40 AM
Answers
-
Hi Sanatan,
Sorry for another link but there's no point me re-explaining the wheel. See http://msdn.microsoft.com/en-us/library/hh675404.aspx for an example of authenticating user in CRM2011.
Michael Palmer
xRMPalmer
@MJFPalmer
Rockstar365
- Marked as answer by JaiHariHar Wednesday, August 28, 2013 7:50 AM
Monday, August 26, 2013 12:21 PM -
Hi
If you are working on crm online then you need to provide device credentials.
otherwise no need.
try this code
string userName = "username@orgname.onmicrosoft.com"; string password = "password"; ClientCredentials credentials = new ClientCredentials(); credentials.UserName.UserName = username; credentials.UserName.Password = Password; string dusername ="11rx1xmpphty25uqgq23j001z"; string duserid ="/nya`b!KjM_Ow/M,3f/ioa"; ClientCredentials deviceCredentials = new ClientCredentials(); deviceCredentials.UserName.UserName = dusername"; deviceCredentials.UserName.Password =duserid"; Uri organizationUri; organizationUri = new Uri("https://crmlahore.api.crm5.dynamics.com/XRMServices/2011/Organization.svc"); Uri homeRealmUri; homeRealmUri = null; using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(organizationUri, homeRealmUri, credentials, deviceCredentials)) {
- Marked as answer by JaiHariHar Wednesday, August 28, 2013 7:50 AM
Monday, August 26, 2013 12:24 PM
All replies
-
Hi Sanatan,
There are several authentication mechanisms built in to the CRM web services. See http://msdn.microsoft.com/en-us/library/gg328497.aspx for a description.
Michael Palmer
xRMPalmer
@MJFPalmer
Rockstar365
- Proposed as answer by MJFPalmer Monday, August 26, 2013 11:09 AM
- Unproposed as answer by JaiHariHar Monday, August 26, 2013 11:37 AM
Monday, August 26, 2013 10:50 AM -
Thanks for the reply. I am new to MS CRM and couldn't understand much about authentication mechanisms from the website (link) you provided. I am currently using following type of code, what do I need to write in the following code for security in authentication mechanism :
string userName = "username@orgname.onmicrosoft.com"; string password = "password"; ClientCredentials Credentials = new ClientCredentials(); Credentials.UserName.UserName = username; Credentials.UserName.Password = password; string organizationName = string.Empty; Uri organizationUrl = new Uri("https://orgname.api.crm5.dynamics.com/XRMServices/2011/Organization.svc"); using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(organizationUrl, null, Credentials, GetDeviceCredentials())) { IOrganizationService service = (IOrganizationService)serviceProxy; var accounts = service.RetrieveMultiple(accountQuery); }
- Edited by JaiHariHar Monday, August 26, 2013 11:41 AM
Monday, August 26, 2013 11:37 AM -
Hi Sanatan,
Sorry for another link but there's no point me re-explaining the wheel. See http://msdn.microsoft.com/en-us/library/hh675404.aspx for an example of authenticating user in CRM2011.
Michael Palmer
xRMPalmer
@MJFPalmer
Rockstar365
- Marked as answer by JaiHariHar Wednesday, August 28, 2013 7:50 AM
Monday, August 26, 2013 12:21 PM -
Hi
If you are working on crm online then you need to provide device credentials.
otherwise no need.
try this code
string userName = "username@orgname.onmicrosoft.com"; string password = "password"; ClientCredentials credentials = new ClientCredentials(); credentials.UserName.UserName = username; credentials.UserName.Password = Password; string dusername ="11rx1xmpphty25uqgq23j001z"; string duserid ="/nya`b!KjM_Ow/M,3f/ioa"; ClientCredentials deviceCredentials = new ClientCredentials(); deviceCredentials.UserName.UserName = dusername"; deviceCredentials.UserName.Password =duserid"; Uri organizationUri; organizationUri = new Uri("https://crmlahore.api.crm5.dynamics.com/XRMServices/2011/Organization.svc"); Uri homeRealmUri; homeRealmUri = null; using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(organizationUri, homeRealmUri, credentials, deviceCredentials)) {
- Marked as answer by JaiHariHar Wednesday, August 28, 2013 7:50 AM
Monday, August 26, 2013 12:24 PM -
Hi
If you are working on crm online then you need to provide device credentials.
otherwise no need.
try this code
string userName = "username@orgname.onmicrosoft.com"; string password = "password"; ClientCredentials credentials = new ClientCredentials(); credentials.UserName.UserName = username; credentials.UserName.Password = Password; string dusername ="11rx1xmpphty25uqgq23j001z"; string duserid ="/nya`b!KjM_Ow/M,3f/ioa"; ClientCredentials deviceCredentials = new ClientCredentials(); deviceCredentials.UserName.UserName = dusername"; deviceCredentials.UserName.Password =duserid"; Uri organizationUri; organizationUri = new Uri("https://crmlahore.api.crm5.dynamics.com/XRMServices/2011/Organization.svc"); Uri homeRealmUri; homeRealmUri = null; using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(organizationUri, homeRealmUri, credentials, deviceCredentials)) {
Thanks for the reply Riaz, I am passing "DeviceCredentials" and "CleintCredentials" in the constructor "OrganizationServiceProxy", but is it enough for the security since the "ClientCredentials" contain username and password. So is there any way I can generate token, access key etc. rather than directly passing username and password ?Monday, August 26, 2013 1:02 PM