ADD: MacCloud/Box: step-114: remove BOX clientSecret from source code and configuration files

This commit is contained in:
rich2014 2025-05-08 21:51:56 +08:00
commit 6afa92c16e
4 changed files with 23 additions and 35 deletions

View file

@ -107,6 +107,9 @@ var
implementation
const
BOX_CLIENT_SECRET = '*';
{ TBoxListFolderSession }
procedure TBoxListFolderSession.listFolderFirst;
@ -525,7 +528,7 @@ begin
params.TOKEN_URI:= BoxConst.URI.TOKEN;
params.REVOKE_TOKEN_URI:= BoxConst.URI.REVOKE_TOKEN;
params.AUTH_TYPE:= 'Bearer';
_authSession:= TCloudDriverOAuth2SecretSession.Create( self, params );
_authSession:= TCloudDriverOAuth2SecretSession.Create( self, params, BOX_CLIENT_SECRET );
end;
function TBoxClient.clone: TCloudDriver;

View file

@ -68,7 +68,7 @@ type
{ TCloudDriverOAuth2PKCESession }
TCloudDriverOAuth2PKCESession = class( TCloudDriverOAuth2Session )
strict private
strict protected
_codeVerifier: String;
protected
procedure onAuthorize( const queryItems: TQueryItemsDictonary ); override;
@ -82,12 +82,18 @@ type
{ TCloudDriverOAuth2SecretSession }
TCloudDriverOAuth2SecretSession = class( TCloudDriverOAuth2Session )
strict protected
_clientSecret: String;
protected
procedure onAuthorize( const queryItems: TQueryItemsDictonary ); override;
procedure onRequestToken( const queryItems: TQueryItemsDictonary ); override;
procedure onRefreshToken( const queryItems: TQueryItemsDictonary ); override;
procedure onRevokeToken( const http: TMiniHttpClient ); override;
public
constructor Create(
const driver: TCloudDriver;
const params: TCloudDriverOAuth2SessionParams;
const clientSecret: String );
function clone(const driver: TCloudDriver): TCloudDriverOAuth2Session; override;
end;
@ -391,7 +397,6 @@ end;
procedure TCloudDriverOAuth2SecretSession.onAuthorize(
const queryItems: TQueryItemsDictonary);
begin
queryItems.Add( 'client_id', _config.clientID );
queryItems.Add( 'token', _token.access );
end;
@ -399,7 +404,7 @@ procedure TCloudDriverOAuth2SecretSession.onRequestToken( const queryItems: TQue
var
secret: String;
begin
secret:= TTokenCloudDriverConfigWithSecret(_config).clientSecret;
secret:= _clientSecret;
queryItems.Add( 'client_secret', secret );
end;
@ -413,7 +418,7 @@ var
queryItems: TQueryItemsDictonary;
secret: String;
begin
secret:= TTokenCloudDriverConfigWithSecret(_config).clientSecret;
secret:= _clientSecret;
queryItems:= TQueryItemsDictonary.Create;
queryItems.Add( 'client_id', _config.clientID );
queryItems.Add( 'client_secret', secret );
@ -421,9 +426,16 @@ begin
http.setQueryParams( queryItems );
end;
constructor TCloudDriverOAuth2SecretSession.Create(const driver: TCloudDriver;
const params: TCloudDriverOAuth2SessionParams; const clientSecret: String);
begin
Inherited Create( driver, params );
_clientSecret:= clientSecret;
end;
function TCloudDriverOAuth2SecretSession.clone( const driver: TCloudDriver ): TCloudDriverOAuth2Session;
begin
Result:= TCloudDriverOAuth2SecretSession.Create( driver, _params );
Result:= TCloudDriverOAuth2SecretSession.Create( driver, _params, _clientSecret );
Result._accountID:= _accountID;
Result._token:= _token.clone;
end;

View file

@ -27,16 +27,6 @@ type
TTokenCloudDriverConfigPtr = ^TTokenCloudDriverConfig;
{ TTokenCloudDriverConfigWithSecret }
TTokenCloudDriverConfigWithSecret = class( TTokenCloudDriverConfig )
private
_clientSecret: String;
public
constructor Create( const aClientID: String; const aClientSecret: String; const aListenURI: String );
property clientSecret: String read _clientSecret;
end;
{ TCloudDriverToken }
TCloudDriverToken = class
@ -79,15 +69,6 @@ begin
_listenURI:= aListenURI;
end;
{ TTokenCloudDriverConfigWithSecret }
constructor TTokenCloudDriverConfigWithSecret.Create(const aClientID: String;
const aClientSecret: String; const aListenURI: String);
begin
Inherited Create( aClientID, aListenURI );
_clientSecret:= aClientSecret;
end;
{ TCloudDriverToken }
function TCloudDriverToken.isValidAccessToken: Boolean;

View file

@ -114,19 +114,13 @@ type
class procedure TWFXTokenCloudDriverConfig.loadDriverCommon(const params: NSDictionary);
var
clientID: String;
clientSecret: String;
listenURI: String;
oldCloudDriverConfig: TTokenCloudDriverConfig;
begin
clientID:= TJsonUtil.getString( params, 'clientID' );
clientSecret:= TJsonUtil.getString( params, 'clientSecret' );
listenURI:= TJsonUtil.getString( params, 'listenURI' );
oldCloudDriverConfig:= self.cloudDriverConfigPtr^;
if clientSecret = EmptyStr then begin
self.cloudDriverConfigPtr^:= TTokenCloudDriverConfig.Create( clientID, listenURI );
end else begin
self.cloudDriverConfigPtr^:= TTokenCloudDriverConfigWithSecret.Create( clientID, clientSecret, listenURI );
end;
self.cloudDriverConfigPtr^:= TTokenCloudDriverConfig.Create( clientID, listenURI );
if Assigned(oldCloudDriverConfig) then
oldCloudDriverConfig.Free;
cloudDriverManager.register( self.cloudDriverClass );
@ -139,8 +133,6 @@ begin
cloudDriverConfig:= self.cloudDriverConfigPtr^;
TJsonUtil.setString( params, 'clientID', cloudDriverConfig.clientID );
TJsonUtil.setString( params, 'listenURI', cloudDriverConfig.listenURI );
if cloudDriverConfig is TTokenCloudDriverConfigWithSecret then
TJsonUtil.setString( params, 'clientSecret', TTokenCloudDriverConfigWithSecret(cloudDriverConfig).clientSecret );
end;
class procedure TWFXTokenCloudDriverConfig.loadConnectionCommon( const driver: TCloudDriver; const params: NSDictionary );
@ -543,7 +535,7 @@ begin
WFXCloudDriverMenuItems.add( TOneDriveClient.driverName, 'OneDrive' );
WFXCloudDriverConfigManager.register( TBoxClient.driverName, TWFXBoxConfig );
boxConfig:= TTokenCloudDriverConfigWithSecret.Create( '', '', 'dc2ea085a05ac273a://box/auth' );
boxConfig:= TTokenCloudDriverConfig.Create( 'rtm1apih0scrk1we9dnzej7fezd9t2xb', 'dc2ea085a05ac273a://box/auth' );
cloudDriverManager.register( TBoxClient );
WFXCloudDriverMenuItems.add( TBoxClient.driverName, 'Box' );