none
How to do Windows Live Authentication for CRM Online in JAVA?

    Вопрос

  • Hello,

    I want to access CRM Online web service through Java.
    For accessing the CRM online web service we need security token (Which we get after Passport/windows Live authentication).
    But I have no knowledge about what is the standard way to do windows live authentication.
    I tried some code samples posted in blogs but none worked.
    Please help on this.
    8 февраля 2010 г. 9:17

Ответы

Все ответы

  • Hi:

    If you give some more details as to what you need to do I might be able to offer more input, but in the past I did this by creating the CRM Authentication code and data parsing in a .NET dll and then calling that code from Java. Are you writing a Java application or a web-based applet?

    John.
    8 февраля 2010 г. 17:34
    Модератор
  • Thanks John,

    It is a Java Application.Did you used JNI for calling .NET DLL from Java?

    Till now what I have tried is as follows:

    (1)Tried the samples provided in SDK to understand ho CRM Online works in .NET.
    (2)Retrieved SOAP Message and URL for passport authentication using HTTP Sniffer tool.
    (2)Now when I try to do same thing in Java using the retrieved SOAP message and URL it fails:
    Here is URL and SOAP message that I am using for passport authentication.
    https://login.live.com/RST2.srf
    <?xml version="1.0" encoding="UTF-8"?>
    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
    	xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
    	xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
    	xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
    	xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:wssc="http://schemas.xmlsoap.org/ws/2005/02/sc"
    	xmlns:wst="http://schemas.xmlsoap.org/ws/2005/02/trust">
    	<s:Header>
    		<wsa:Action s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue</wsa:Action>
    		<wsa:To s:mustUnderstand="1">HTTPS://login.live.com:443//RST2.srf</wsa:To>
    		<wsa:MessageID>1265627255</wsa:MessageID>
    		<ps:AuthInfo
    			xmlns:ps="http://schemas.microsoft.com/Passport/SoapServices/PPCRL"
    			Id="PPAuthInfo">
    			<ps:HostingApp>{52B7DF4E-8D6F-49B5-BA7A-2E77B06DF104}</ps:HostingApp>
    			<ps:BinaryVersion>5</ps:BinaryVersion>
    			<ps:UIVersion>1</ps:UIVersion>
    			<ps:Cookies></ps:Cookies>
    			<ps:RequestParams>AQAAAAIAAABsYwQAAAAxMDMz</ps:RequestParams>
    		</ps:AuthInfo>
    		<wsse:Security>
    			<wsse:UsernameToken wsu:Id="user">
    				<wsse:Username>abc@abc.com</wsse:Username>
    				<wsse:Password>password</wsse:Password>
    			</wsse:UsernameToken>
    			<wsu:Timestamp Id="Timestamp">
    				<wsu:Created>2010-02-08T11:07:36Z</wsu:Created>
    				<wsu:Expires>2010-02-08T11:12:36Z</wsu:Expires>
    			</wsu:Timestamp>
    		</wsse:Security>
    	</s:Header>
    	<s:Body>
    		<wst:RequestSecurityToken Id="RST0">
    			<wst:RequestType>http://schemas.xmlsoap.org/ws/2005/02/trust/Issue</wst:RequestType>
    			<wsp:AppliesTo>
    				<wsa:EndpointReference>
    					<wsa:Address>http://Passport.NET/tb</wsa:Address>
    				</wsa:EndpointReference>
    			</wsp:AppliesTo>
    			<wsp:PolicyReference URI="MBI_SSL"></wsp:PolicyReference>
    		</wst:RequestSecurityToken>
    	</s:Body>
    </s:Envelope>

    The above request I tried through JAVA SOAP API as well as Apache HTTPClient.For SOAP API its throwing exception  "Incoming Message stream is null" and for HTTP Client its simply returning complete Sign in web page.

    Code snippet using Java SOAP API:
       try {
                SOAPMessage message;
                SOAPConnection conn;
                
                BufferedReader bif = new BufferedReader(new FileReader("passportRequest.xml"));
                
                String request = "";
                
                while (true) {
                    String ss = bif.readLine();
                    if (ss != null)
                        request = request + ss;
                    else
                        break;
                    
                }
                
                // Create SoapMessage
                MessageFactory msgFactory = MessageFactory.newInstance();
                message = msgFactory.createMessage();
                SOAPPart soapPart = message.getSOAPPart();
                
                // Load the SOAP text into a stream source
                byte[] buffer = request.getBytes();
                ByteArrayInputStream stream = new ByteArrayInputStream(buffer);
                StreamSource source = new StreamSource(stream);
                
                // Set contents of message
                soapPart.setContent(source);
                
                SOAPBody soapBody = message.getSOAPBody();
                conn = SOAPConnectionFactory.newInstance().createConnection();
                SOAPMessage response = conn.call(message, fURL);
                SOAPBody body = response.getSOAPBody();
                conn.close();
                
            }
            catch (SOAPException e) {
                System.out.println("SOAPException : " + e);
                
            }
            catch (IOException e) {
                System.out.println("IOException : " + e);
            }

    Thanks,
    Harvinder
    9 февраля 2010 г. 3:50
  • Hello, I am also interested in enabling CRM and SAML 2.0.  Is there updated information available on this thread?  Thank you!

     

    rjcarroll

    www.ssoeasy.com

    4 октября 2010 г. 17:55
  • http://www.dynamicslight.com/2010/04/mscrm-development-tips-tricks-3-connecting-to-mscrm-online/

    The blog posting above appears to completely dissect the interaction with Windows Live for authentication to CRM Online in raw SOAP calls.  Though the solution is programmed in C#, I suspect that it wouldn't be difficult to translate into JAVA.  There doesn't appear to be a necessity to use the .Net assembly for Live authentication which is included with the CRM SDK.


    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    4 октября 2010 г. 18:08
    Модератор
  • Thank you!  This is extremely helpful!

     

    rjcarroll www.ssoeasy.com

    6 октября 2010 г. 3:39