Skip to main content

To demonstrate the problem, I will be utilizing CData Google Analytics JDBC and ADO.NET Drivers as examples. However, it is important to note that this error can occur in any OAuth data source.  

When trying to authenticate with OAuth, one of the most important things of the whole OAuth flow is the OAuthSettings file.  

When the driver redirects you to the web browser to initiate OAuth and you grant permissions, the driver sends a request in the Data Source’s API with the Authorization Code retrieved from the web URL to obtain an Access Token and a Refresh Token. If these values weren’t saved somewhere, the driver would have to redirect to the web browser each time you made a connection, which isn’t very practical. This is the reason why the OAuthSettings file holds a major importance in OAuth flow. 

After retrieving the OAuth tokens, the driver creates an OAuthSettings.txt file in the path of “OAuthSettingsLocation” connection property. In JDBC and ADO.NET (Windows platform), by default, this location is: 

%APPDATA%\CData\GoogleAnalytics Data Provider\OAuthSettings.txt 

For the driver to be able to create this .txt file and write/re-write it (in case of refreshing the Access Token), the user needs to have full-access permission to this file path. 

The default path that is set in the OAuthSettingsLocation property has full-access permissions for the current user. However, there might be cases where these permissions are altered, and the user doesn’t have read/write permissions, or it could be that the user has set a custom OAuthSettingsLocation path such as: 

“C:\Users\BrajanHasmeta\OAuth\OAuthSettings.txt”, 

and this custom path doesn’t have read/write permissions for the user who is accessing it. 

In these cases, the driver throws an Access is denied error.  

 

In JDBC, the error would look like the following:  

Test connection failed. Error: Access is denied” 

 

 

 

 

In ADO.NET, the error is more specific, and it explains in which path the access is denied: 

“Access to the path 'C:\Users\BrajanHasmeta\AppData\Roaming\CData\GoogleAnalytics Data Provider\OAuthSettings.txt.lock' is denied.” 

 

 

There are two ways to fix this problem: 

1. The easiest one is to set the OAuthSettingsLocation property to a Public path, such as: 

“C:\Users\Public\Documents\OAuthSettings.txt” 

NOTE: The Public Documents folder can normally be accessed by all users on the machine, however, it doesn’t mean that it can’t be altered. That said, if the Public path does not work, you may need to locate a path that guarantees full-access permissions. 

2. The second way is by modifying the permissions of your folder that contains the OAuthSettings.txt file. To do so, open “File Explorer”, and go to the file path that is specified in the OAuthSettingsLocation property. Right-click the folder that contains your OAuthSettings.txt file >> Click Properties >> Go to Security. After clicking Edit, the “Permissions” tab will show up. After this, select the user you want to grant access to, and check the Allow box for the “Full Control” permission level. Then, click Apply >> click OK