zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    绕过校园网认证实现免费上网【三端】
    Java多线程下载器FileDownloader(支持断点续传、代理等功能)
    Java实现命令行中的进度条功能
    记一次基于Cloudflare服务的爬虫
    如何修改npm包源码后,重新npm包的时候能是修改后的版本
    将html片段的文本内容取出来
    阿里云的oss的文件资源链接强制下载
    常用正则记录
    flvjs的unload(),detachMediaElement(),destroy()报错,undefined,not a function解决方案
    微信扫码登陆,qq登陆,微博登陆等第三方登陆成功后返回原来的页面并进行跳转
  • 原文地址:https://www.cnblogs.com/lingzhao/p/4552061.html
Copyright © 2011-2022 走看看