Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

Java Examples

Web API Categories

ASN.1
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
Geolocation
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text

HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(Java) SharePoint Online Authentication

Demonstrates how to authenticate with SharePoint Online. The end result of authentication is to establish an HTTP cookie, named "SPOIDCRL", that contains a binary security token to be sent in subsequent SharePoint HTTPS requests.

The SPOIDCRL cookie can be persisted to a file and re-used in subsequent application runs.

Important: This example uses a method, SharePointOnlineAuth, that is introduced in Chilkat v9.5.0.73.

Also Important: Chilkat realizes there may be cases where your situation is such that it does not work, and something additional is required to make it work. If the example does not work out-of-the-box, please send email to support@chilkatsoft.com. The information logged to the LastErrorText property has been carefully crafted to help solve problems quickly. Also, the JSON argument to the SharePointOnlineAuth method provides a means to include additional information, whatever it may be, to handle future unknown situations.

Chilkat Java Downloads

Java Libs for Windows, Linux, Alpine Linux,
MAC OS X, Solaris, FreeBSD, OpenBSD,
Raspberry Pi and other single board computers

Java Libs for Android

import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    //  This requires the Chilkat API to have been previously unlocked.
    //  See Global Unlock Sample for sample code.

    boolean success;
    CkHttp http = new CkHttp();

    //  Change these things...
    //  Make sure to use "https" and end in a "/".
    String siteUrl = "https://mydomain.sharepoint.com/";
    //  The username is an email address.
    String username = "username@mydomain.com";

    //  The jsonExtra is for future use, if extra information is required for particular integrations.
    CkJsonObject jsonExtra = new CkJsonObject();

    CkSecureString ssPassword = new CkSecureString();
    ssPassword.Append("mypassword");

    //  Set properties to save/send cookies, and specify a cookie directory.
    //  If the CookieDir = "memory", then the SPOIDCRL cookie is persisted in memory for this HTTP object instance only.
    //  To persist the SharePoint authentication cookie for other HTTP objects, and for future application runs,
    //  set the CookieDir equal to a directory path (not a specific file path, but a directory path where cookie files
    //  are to be created).
    http.put_SaveCookies(true);
    http.put_SendCookies(true);
    http.put_CookieDir("memory");

    //  The SharePointOnlineAuth method is introduced in Chilkat v9.5.0.73
    success = http.SharePointOnlineAuth(siteUrl,username,ssPassword,jsonExtra);
    if (success == false) {
        System.out.println(http.lastErrorText());
        return;
        }

    System.out.println("Success! We have the SPOIDCRL cookie...");

    //  SharePoint authenticated requests may now be sent because the authentication cookie is automatically included.
    //  For example:
    CkStringBuilder sbResponseXml = new CkStringBuilder();
    success = http.QuickGetSb("https://mydomain.sharepoint.com/_api/web/GetFolderByServerRelativeUrl('/Documents')/Files",sbResponseXml);
    if (success == false) {
        System.out.println(http.lastErrorText());
        return;
        }

    System.out.println("Response status code = " + http.get_LastStatus());

    CkXml xml = new CkXml();
    xml.LoadSb(sbResponseXml,true);
    System.out.println(xml.getXml());
  }
}

 

© 2000-2019 Chilkat Software, Inc. All Rights Reserved.