• Question about iOS application and Domino Data Service

    By yang li 1 decade ago

    Hi,
    I am testing solution to access Domino data via iOS native application. According documentation, I make a iOS app to read data form Domino, it is perfect working. But I have problem to PUT/POST doc because authentication.

    So, my question is: How to do basic authentication “HTTP Authorization header” or session authentication?

    I search on internet and found something as below, but system response require name&password.

    NSString *bytes = [NSString stringWithFormat:@“{"DocType":"TestByREST","Form":"RESTForm"}“];

    NSURL *url=[NSURL URLWithString:@"http://myServerAddress:80/myDominoDB.nsf/api/data/collections"];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    [request setValue:@"Basic eWFuZxUyMGxpJTNBdGlhb3BlcSU3RTU2" forHTTPHeaderField:@"Authorization"];
    [request setHTTPMethod:@"POST"];
    NSData *req=[NSData dataWithBytes:[bytes UTF8String] length:[bytes length]];
    [request setHTTPBody:req];
    NSData * responseData = nil;
    responseData = [NSMutableData data];
    NSURLResponse* response;
    NSError* error = nil;
    responseData = [NSURLConnection sendSynchronousRequest:request
                                         returningResponse:&response
                                                     error:&error];
    NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
    
    NSLog(@"the final output is:%@",responseString);
    

    ===================
    I also try add user name & password in url, like:
    http://myServerAddress:80/names.nsf?login&username=xxxxxx&password=xxxxxx&redirectto=myDominoDB.nsf/api/data/documents”];
    But not work also.

    Anybody can help? It is great if can provide some example codes (Object-C is perfect) to PUT/POST/DELETE documents by Domino.

    Thanks again to develop this REST service, it make domino able to extend to mobile device.

    • Have you tried basic authentication?

      By Dave Delay 1 decade ago

      Domino supports both basic authentication and session authentication.  For a quick description of the differences see Richard Schwartz's comment here:

       

      http://stackoverflow.com/questions/21533730/how-to-authenticate-users-in-lotus-domino-8-5-3-through-domino-data-service-rest

       

      Even when a server is configured for session authentication, it usually allows basic authentication for any HTTP request.  In my opinion, basic authentication is easier to implement from a native mobile application.  You just need to encode the user name and password in an Authorization header as described here:

       

      http://en.wikipedia.org/wiki/Basic_access_authentication

       

      Of course, your application will want to prompt for the user name and password once and reuse the credentials for each request. And it will want to handle the case where the password changes on the server.  Finally, if your application stores a Domino user name and password on the mobile device, you should think about encrypting the credentials. 

       

      -- Dave

      • By yang li 1 decade ago

        Thanks for detail reply. I will try them.

        • By yang li 1 decade ago

          Problem solved, thanks.
          I found a better way which base on AFNetworking.

          ===========================

          AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

          [manager setRequestSerializer:[AFHTTPRequestSerializer serializer]];
          [manager.requestSerializer setAuthorizationHeaderFieldWithUsername:@"User Notes ID" password:@"User Password"];