Site Map Contact Us Home
E-mail Newsletter
Subscribe to get informed about
Clever Components news.

Your Name:
Your Email:
 
SUBSCRIBE
 
Previous Newsletters
 




Products Articles Downloads Order Support
Customer Portal      

OAUTH and cloud services (Yandex Disk)

Yandex.Disk

This article demonstrates how to use the Clever Internet Suite components for implementing the OAUTH authorization and accessing cloud services, such as Yandex.Disk.

The Clever Internet Suite provides a special OAuth component that initiates the OAUTH 2.0 authorization process and obtains the authorization token. This token can be used by any component (not only Clever Internet Suite) for authorizing at online service.

// [Delphi]
clOAuth1.AuthorizationFlow := afAuthCodeFlow;
clOAuth1.AuthorizationEndPoint := apLocalWebServer;
clOAuth1.EscapeRedirectURL := False;

clOAuth1.AuthURL := 'https://oauth.yandex.ru/authorize';
clOAuth1.TokenURL := 'https://oauth.yandex.ru/token';
clOAuth1.RedirectURL := 'http://localhost';
clOAuth1.LocalWebServerPort := 55896;
clOAuth1.ClientID := '1335c5e0cf6d4c2f96661d5d76a86117';
clOAuth1.ClientSecret := '5e0689f4ce86415c856f113fa75eb98b';
clOAuth1.Scope := 'unit_test';

clWebDav1.Authorization := clOAuth1.GetAuthorization();

Yandex.Disk provides WebDAV interface for accessing its cloud service. Let's use the WebDAV component that fully supports OAUTH.

// [Delphi]
clWebDav1.CharSet := 'UTF-8';
clWebDav1.Depth := wdResourceAndChildren;
clWebDav1.SilentHTTP := True;
clWebDav1.Expect100Continue := True;
clWebDav1.TLSFlags := [tfUseTLS, tfUseTLS11];

clWebDav1.GetProperties('https://webdav.yandex.ru/', ['displayname']);
ListBox1.Clear();
FDirList.Clear();

for i := 0 to clWebDav1.ResourceProperties.Count - 1 do
begin
   ListBox1.Items.Add(clWebDav1.ResourceProperties[i].Value);

   uri := clWebDav1.ResourceProperties[i].Uri;
   if (Pos('http', LowerCase(uri)) <> 1) then
   begin
      uri := TclUrlParser.CombineUrl(uri, 'https://webdav.yandex.ru/');
   end;

   FDirList.Add(uri);
end;

The complete source code for the samples from this article can be downloaded on GitHub

Download free trial of Clever Internet Suite: Download

Learn more about OAuth and WebDAV components: Clever Internet Sute

Ask questions: Customer Portal

Kind regards
Sergey Shirokov
Clever Components team

    Copyright © 2000-2024