• sharepoint services


    I have got solution for authentication to share point web service I have use fedAuth Cookie and rtfa Cookie to pass credential

    Fisrt I have load the login page in webview and to load login page of sharepoint

    When user done with login i will store those Cookie with following method

    func verifyCookies()
    {
    
        var status = 0
        var cookieArray:NSArray = storage.cookies!
    
        for cookie in cookieArray
        {
            if cookie.name == "FedAuth"
            {
                fedAuthCookie = cookie as NSHTTPCookie
                status++
                continue;
            }
            else if cookie.name == "rtFa"
            {
                status++
                rtFaCookie = cookie as NSHTTPCookie
            }
        }
    
        if status == 2
        {
            self.webView.hidden = true
            self.cookieFound(rtFaCookie,fedAuthCookie: fedAuthCookie) // method mention below.
        }
    
    }

    fedAuthCookie and rtFaCookie are variable name which store that cookie

    And after that I have use those cookie to pass credential to my request.

    Below is my request code

    func cookieFound(rtFaCookie:NSHTTPCookie,fedAuthCookie:NSHTTPCookie)
    {
        var message:String = "<?xml version='1.0' encoding='utf-8'?><soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body><GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'><listName>demo</listName><viewName></viewName><query></query><viewFields></viewFields><rowLimit></rowLimit><QueryOptions></QueryOptions><webID></webID></GetListItems></soap:Body></soap:Envelope>"
    
        var messageLength = String(countElements(message))
        var url = NSURL(string: "https://domain/_vti_bin/Lists.asmx")
        var therequest = NSMutableURLRequest(URL: url!)
    
        therequest.addValue(messageLength, forHTTPHeaderField: "Content-Length")
        therequest.addValue("text/xml; charset=utf-8", forHTTPHeaderField: "Content-Type")
        therequest.addValue("http://schemas.microsoft.com/sharepoint/soap/GetListItems", forHTTPHeaderField: "SOAPAction")
    
        // Authentication is passed in request header
    
        var cookieArray = NSArray(objects: rtFaCookie,fedAuthCookie)
        var cookieHeaders = NSHTTPCookie.requestHeaderFieldsWithCookies(cookieArray)
        var requestHeaders = NSDictionary(dictionary: cookieHeaders)
    
    
        therequest.allHTTPHeaderFields = requestHeaders
        therequest.HTTPMethod = "POST"
        therequest.HTTPBody = message.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
        var connection = NSURLConnection(request: therequest, delegate: self, startImmediately: true)
        connection?.start()
    
    
    }

    I have called verifyCookies() method from below webView methods

    func webViewDidStartLoad(webView: UIWebView) {
        self.verifyCookies()
    }
    func webViewDidFinishLoad(webView: UIWebView) {
        self.verifyCookies()
    }

    Hope it will help someone

  • 相关阅读:
    Winform中怎样设置ContextMenuStrip右键菜单的选项ToolStripMenuItem添加照片
    JavaScript垃圾回收机制
    前端如何处理内存泄漏
    前端缓存
    深入理解vue-router之keep-alive
    (淘宝无限适配)手机端rem布局详解
    mysql不会使用索引,导致全表扫描情况
    MYSQL性能优化的最佳20+条经验
    深拷贝与浅拷贝的区别,实现深拷贝的几种方法
    vue组件通信方式总结
  • 原文地址:https://www.cnblogs.com/lingzhao/p/4552061.html
Copyright © 2020-2023  润新知