mirror of
https://github.com/doublecmd/doublecmd.git
synced 2026-06-21 09:58:13 +00:00
UPD: MacCloud: step-80: unify the reference of Http Authorization Header
This commit is contained in:
parent
eced841224
commit
8cc89f6444
6 changed files with 29 additions and 52 deletions
|
|
@ -522,7 +522,6 @@ begin
|
|||
params.OAUTH2_URI:= BoxConst.URI.OAUTH2;
|
||||
params.TOKEN_URI:= BoxConst.URI.TOKEN;
|
||||
params.REVOKE_TOKEN_URI:= BoxConst.URI.REVOKE_TOKEN;
|
||||
params.AUTH_HEADER:= BoxConst.HEADER.AUTH;
|
||||
params.AUTH_TYPE:= 'Bearer';
|
||||
_authSession:= TCloudDriverOAuth2SecretSession.Create( self, params );
|
||||
end;
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ type
|
|||
_parentPath: String;
|
||||
_parentID: String;
|
||||
public
|
||||
constructor Create( const authSession: TCloudDriverOAuth2Session; const path: String );
|
||||
constructor Create( const authSession: TCloudDriverAuthSession; const path: String );
|
||||
function toJsonString: NSString;
|
||||
public
|
||||
property filename: String read _filename;
|
||||
|
|
@ -38,7 +38,7 @@ type
|
|||
const path: String;
|
||||
const raiseException: Boolean = True ): String;
|
||||
class function pathToFileID(
|
||||
const authSession: TCloudDriverOAuth2Session;
|
||||
const authSession: TCloudDriverAuthSession;
|
||||
const path: String;
|
||||
const raiseException: Boolean = True ): String;
|
||||
end;
|
||||
|
|
@ -67,7 +67,6 @@ type
|
|||
end;
|
||||
|
||||
TBoxConstHeader = record
|
||||
AUTH: String;
|
||||
ARG: String;
|
||||
RESULT: String;
|
||||
end;
|
||||
|
|
@ -94,7 +93,6 @@ const
|
|||
UPLOAD_LARGE: 'https://upload.box.com/api/2.0/files/upload_sessions';
|
||||
);
|
||||
HEADER: (
|
||||
AUTH: 'Authorization';
|
||||
ARG: 'Dropbox-API-Arg';
|
||||
RESULT: 'Dropbox-API-Result';
|
||||
);
|
||||
|
|
@ -185,7 +183,7 @@ end;
|
|||
{ TBoxPathComponents }
|
||||
|
||||
constructor TBoxPathComponents.Create(
|
||||
const authSession: TCloudDriverOAuth2Session; const path: String);
|
||||
const authSession: TCloudDriverAuthSession; const path: String);
|
||||
begin
|
||||
_fullPath:= path;
|
||||
_parentPath:= TFileUtil.parentPath( _fullPath );
|
||||
|
|
@ -219,7 +217,7 @@ begin
|
|||
end;
|
||||
|
||||
class function TBoxClientUtil.pathToFileID(
|
||||
const authSession: TCloudDriverOAuth2Session;
|
||||
const authSession: TCloudDriverAuthSession;
|
||||
const path: String;
|
||||
const raiseException: Boolean ): String;
|
||||
var
|
||||
|
|
@ -267,7 +265,7 @@ var
|
|||
Exit;
|
||||
|
||||
case httpResult.resultCode of
|
||||
401: raise ECloudDriverTokenException.Create( cloudDriverMessage );
|
||||
401: raise ECloudDriverAuthException.Create( cloudDriverMessage );
|
||||
else raise ECloudDriverException.Create( cloudDriverMessage );
|
||||
end;
|
||||
end;
|
||||
|
|
|
|||
|
|
@ -121,7 +121,6 @@ type
|
|||
end;
|
||||
|
||||
TDropBoxConstHeader = record
|
||||
AUTH: String;
|
||||
ARG: String;
|
||||
RESULT: String;
|
||||
end;
|
||||
|
|
@ -156,7 +155,6 @@ const
|
|||
MOVE: 'https://api.dropboxapi.com/2/files/move_v2';
|
||||
);
|
||||
HEADER: (
|
||||
AUTH: 'Authorization';
|
||||
ARG: 'Dropbox-API-Arg';
|
||||
RESULT: 'Dropbox-API-Result';
|
||||
);
|
||||
|
|
@ -191,7 +189,7 @@ var
|
|||
procedure processDropBox401Error;
|
||||
begin
|
||||
if cloudDriverMessage.IndexOf('access_token') >= 0 then
|
||||
raise ECloudDriverTokenException.Create( cloudDriverMessage );
|
||||
raise ECloudDriverAuthException.Create( cloudDriverMessage );
|
||||
raise ECloudDriverException.Create( cloudDriverMessage );
|
||||
end;
|
||||
|
||||
|
|
@ -639,7 +637,6 @@ begin
|
|||
params.OAUTH2_URI:= DropBoxConst.URI.OAUTH2;
|
||||
params.TOKEN_URI:= DropBoxConst.URI.TOKEN;
|
||||
params.REVOKE_TOKEN_URI:= DropBoxConst.URI.REVOKE_TOKEN;
|
||||
params.AUTH_HEADER:= DropBoxConst.HEADER.AUTH;
|
||||
params.AUTH_TYPE:= 'Bearer';
|
||||
_authSession:= TCloudDriverOAuth2PKCESession.Create( self, params );
|
||||
end;
|
||||
|
|
|
|||
|
|
@ -107,13 +107,8 @@ type
|
|||
RESOURCES: String;
|
||||
end;
|
||||
|
||||
TOneDriveConstHeader = record
|
||||
AUTH: String;
|
||||
end;
|
||||
|
||||
TOneDriveConst = record
|
||||
URI: TOneDriveConstURI;
|
||||
HEADER: TOneDriveConstHeader;
|
||||
end;
|
||||
|
||||
const
|
||||
|
|
@ -124,9 +119,6 @@ const
|
|||
REVOKE_TOKEN: 'https://login.microsoftonline.com/common/oauth2/v2.0/logout';
|
||||
RESOURCES: 'https://graph.microsoft.com/v1.0';
|
||||
);
|
||||
HEADER: (
|
||||
AUTH: 'Authorization';
|
||||
);
|
||||
);
|
||||
|
||||
function toOneDriveResourceItemPath( const path: String; const action: String = '' ): String;
|
||||
|
|
@ -180,7 +172,7 @@ var
|
|||
Exit;
|
||||
case httpResult.resultCode of
|
||||
401:
|
||||
raise ECloudDriverTokenException.Create( cloudDriverMessage );
|
||||
raise ECloudDriverAuthException.Create( cloudDriverMessage );
|
||||
403:
|
||||
raise ECloudDriverPermissionException.Create( cloudDriverMessage );
|
||||
404:
|
||||
|
|
@ -546,7 +538,6 @@ begin
|
|||
params.OAUTH2_URI:= OneDriveConst.URI.OAUTH2;
|
||||
params.TOKEN_URI:= OneDriveConst.URI.TOKEN;
|
||||
params.REVOKE_TOKEN_URI:= OneDriveConst.URI.REVOKE_TOKEN;
|
||||
params.AUTH_HEADER:= OneDriveConst.HEADER.AUTH;
|
||||
params.AUTH_TYPE:= 'Bearer';
|
||||
_authSession:= TCloudDriverOAuth2PKCESession.Create( self, params );
|
||||
end;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ type
|
|||
{ ECloudDriverException }
|
||||
|
||||
ECloudDriverException = class( Exception );
|
||||
ECloudDriverTokenException = class( ECloudDriverException );
|
||||
ECloudDriverAuthException = class( ECloudDriverException );
|
||||
ECloudDriverConflictException = class( ECloudDriverException );
|
||||
ECloudDriverQuotaException = class( ECloudDriverException );
|
||||
ECloudDriverPermissionException = class( ECloudDriverException );
|
||||
|
|
@ -174,7 +174,6 @@ type
|
|||
OAUTH2_URI: String;
|
||||
TOKEN_URI: String;
|
||||
REVOKE_TOKEN_URI: String;
|
||||
AUTH_HEADER: String;
|
||||
AUTH_TYPE: String;
|
||||
end;
|
||||
|
||||
|
|
@ -275,13 +274,13 @@ type
|
|||
|
||||
TCloudDriverDownloadSession = class
|
||||
protected
|
||||
_authSession: TCloudDriverOAuth2Session;
|
||||
_authSession: TCloudDriverAuthSession;
|
||||
_serverPath: String;
|
||||
_localPath: String;
|
||||
_callback: ICloudProgressCallback;
|
||||
public
|
||||
constructor Create(
|
||||
const authSession: TCloudDriverOAuth2Session;
|
||||
const authSession: TCloudDriverAuthSession;
|
||||
const serverPath: String;
|
||||
const localPath: String;
|
||||
const callback: ICloudProgressCallback );
|
||||
|
|
@ -292,14 +291,14 @@ type
|
|||
|
||||
TCloudDriverUploadSession = class
|
||||
protected
|
||||
_authSession: TCloudDriverOAuth2Session;
|
||||
_authSession: TCloudDriverAuthSession;
|
||||
_serverPath: String;
|
||||
_localPath: String;
|
||||
_localFileSize: Integer;
|
||||
_callback: ICloudProgressCallback;
|
||||
public
|
||||
constructor Create(
|
||||
const authSession: TCloudDriverOAuth2Session;
|
||||
const authSession: TCloudDriverAuthSession;
|
||||
const serverPath: String;
|
||||
const localPath: String;
|
||||
const callback: ICloudProgressCallback );
|
||||
|
|
@ -310,10 +309,10 @@ type
|
|||
|
||||
TCloudDriverCreateFolderSession = class
|
||||
protected
|
||||
_authSession: TCloudDriverOAuth2Session;
|
||||
_authSession: TCloudDriverAuthSession;
|
||||
_path: String;
|
||||
public
|
||||
constructor Create( const authSession: TCloudDriverOAuth2Session; const path: String );
|
||||
constructor Create( const authSession: TCloudDriverAuthSession; const path: String );
|
||||
procedure createFolder; virtual; abstract;
|
||||
end;
|
||||
|
||||
|
|
@ -321,11 +320,11 @@ type
|
|||
|
||||
TCloudDriverDeleteSession = class
|
||||
protected
|
||||
_authSession: TCloudDriverOAuth2Session;
|
||||
_authSession: TCloudDriverAuthSession;
|
||||
_path: String;
|
||||
_isFolder: Boolean;
|
||||
public
|
||||
constructor Create( const authSession: TCloudDriverOAuth2Session;
|
||||
constructor Create( const authSession: TCloudDriverAuthSession;
|
||||
const path: String; const isFolder: Boolean );
|
||||
procedure delete; virtual; abstract;
|
||||
end;
|
||||
|
|
@ -334,13 +333,13 @@ type
|
|||
|
||||
TCloudDriverCopyMoveSession = class
|
||||
protected
|
||||
_authSession: TCloudDriverOAuth2Session;
|
||||
_authSession: TCloudDriverAuthSession;
|
||||
_fromPath: String;
|
||||
_toPath: String;
|
||||
_isFolder: Boolean;
|
||||
public
|
||||
constructor Create(
|
||||
const authSession: TCloudDriverOAuth2Session;
|
||||
const authSession: TCloudDriverAuthSession;
|
||||
const fromPath: String;
|
||||
const toPath: String;
|
||||
const isFolder: Boolean );
|
||||
|
|
@ -508,7 +507,7 @@ end;
|
|||
{ TCloudDriverDownloadSession }
|
||||
|
||||
constructor TCloudDriverDownloadSession.Create(
|
||||
const authSession: TCloudDriverOAuth2Session;
|
||||
const authSession: TCloudDriverAuthSession;
|
||||
const serverPath: String;
|
||||
const localPath: String;
|
||||
const callback: ICloudProgressCallback );
|
||||
|
|
@ -522,7 +521,7 @@ end;
|
|||
{ TCloudDriverUploadSession }
|
||||
|
||||
constructor TCloudDriverUploadSession.Create(
|
||||
const authSession: TCloudDriverOAuth2Session;
|
||||
const authSession: TCloudDriverAuthSession;
|
||||
const serverPath: String;
|
||||
const localPath: String;
|
||||
const callback: ICloudProgressCallback );
|
||||
|
|
@ -537,7 +536,7 @@ end;
|
|||
{ TCloudDriverCreateFolderSession }
|
||||
|
||||
constructor TCloudDriverCreateFolderSession.Create(
|
||||
const authSession: TCloudDriverOAuth2Session; const path: String);
|
||||
const authSession: TCloudDriverAuthSession; const path: String);
|
||||
begin
|
||||
_authSession:= authSession;
|
||||
_path:= path;
|
||||
|
|
@ -546,7 +545,7 @@ end;
|
|||
{ TCloudDriverDeleteSession }
|
||||
|
||||
constructor TCloudDriverDeleteSession.Create(
|
||||
const authSession: TCloudDriverOAuth2Session;
|
||||
const authSession: TCloudDriverAuthSession;
|
||||
const path: String; const isFolder: Boolean );
|
||||
begin
|
||||
_authSession:= authSession;
|
||||
|
|
@ -557,7 +556,7 @@ end;
|
|||
{ TCloudDriverCopyMoveSession }
|
||||
|
||||
constructor TCloudDriverCopyMoveSession.Create(
|
||||
const authSession: TCloudDriverOAuth2Session;
|
||||
const authSession: TCloudDriverAuthSession;
|
||||
const fromPath: String;
|
||||
const toPath: String;
|
||||
const isFolder: Boolean );
|
||||
|
|
@ -733,7 +732,7 @@ begin
|
|||
doRequest;
|
||||
|
||||
if cloudDriverResult.httpResult.resultCode <> 200 then
|
||||
raise ECloudDriverTokenException.Create( 'RefreshToken Error' );
|
||||
raise ECloudDriverAuthException.Create( 'RefreshToken Error' );
|
||||
self.analyseTokenResult( cloudDriverResult.httpResult.body );
|
||||
cloudDriverManager.driverUpdated( _driver );
|
||||
finally
|
||||
|
|
@ -779,7 +778,7 @@ function TCloudDriverOAuth2Session.getAccessToken: String;
|
|||
end;
|
||||
end;
|
||||
except
|
||||
on e: ECloudDriverTokenException do begin
|
||||
on e: ECloudDriverAuthException do begin
|
||||
TLogUtil.logError( 'Token Error: ' + e.ClassName + ': ' + e.Message );
|
||||
_token.invalid;
|
||||
self.authorize;
|
||||
|
|
@ -847,9 +846,11 @@ end;
|
|||
procedure TCloudDriverOAuth2Session.setAuthHeader( const http: TMiniHttpClient );
|
||||
var
|
||||
access: String;
|
||||
authString: NSString;
|
||||
begin
|
||||
access:= self.getAccessToken;
|
||||
http.addHeader( _params.AUTH_HEADER, _params.AUTH_TYPE + ' ' + access );
|
||||
authString:= StringToNSString( _params.AUTH_TYPE + ' ' + access );
|
||||
http.addHeader( HttpConst.Header.Authorization, authString );
|
||||
end;
|
||||
|
||||
procedure TCloudDriverOAuth2Session.setToken(const token: TCloudDriverToken);
|
||||
|
|
|
|||
|
|
@ -114,13 +114,8 @@ type
|
|||
MOVE: String;
|
||||
end;
|
||||
|
||||
TYandexConstHeader = record
|
||||
AUTH: String;
|
||||
end;
|
||||
|
||||
TYandexConst = record
|
||||
URI: TYandexConstURI;
|
||||
HEADER: TYandexConstHeader;
|
||||
end;
|
||||
|
||||
const
|
||||
|
|
@ -135,9 +130,6 @@ const
|
|||
COPY: 'https://cloud-api.yandex.net/v1/disk/resources/copy';
|
||||
MOVE: 'https://cloud-api.yandex.net/v1/disk/resources/move';
|
||||
);
|
||||
HEADER: (
|
||||
AUTH: 'Authorization';
|
||||
);
|
||||
);
|
||||
|
||||
// raise the corresponding exception if there are errors
|
||||
|
|
@ -170,7 +162,7 @@ var
|
|||
Exit;
|
||||
case httpResult.resultCode of
|
||||
401:
|
||||
raise ECloudDriverTokenException.Create( cloudDriverMessage );
|
||||
raise ECloudDriverAuthException.Create( cloudDriverMessage );
|
||||
403, 507:
|
||||
raise ECloudDriverQuotaException.Create( cloudDriverMessage );
|
||||
404:
|
||||
|
|
@ -527,7 +519,6 @@ begin
|
|||
params.OAUTH2_URI:= YandexConst.URI.OAUTH2;
|
||||
params.TOKEN_URI:= YandexConst.URI.TOKEN;
|
||||
params.REVOKE_TOKEN_URI:= YandexConst.URI.REVOKE_TOKEN;
|
||||
params.AUTH_HEADER:= YandexConst.HEADER.AUTH;
|
||||
params.AUTH_TYPE:= 'OAuth';
|
||||
_authSession:= TCloudDriverOAuth2PKCESession.Create( self, params );
|
||||
end;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue