Skip to content

Commit 7122663

Browse files
committed
✨ Feat: add oauth scopes configuration option
1 parent 10d1852 commit 7122663

File tree

7 files changed

+35
-11
lines changed

7 files changed

+35
-11
lines changed

CHANGELOG.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Changelog
22

3-
## 1.3.3
3+
## 1.3.4
4+
5+
- Feature: Add OAuth Scopes Configuration
6+
7+
---
8+
9+
### 1.3.3
410

511
- Feature: Add additional connection & query editor config options
612

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ Available configuration fields are as follows:
7575
| Client Secret | Databricks Service Principal Client Secret. (only if OAuth / OAuth2 is chosen as Auth Method) |
7676
| Access Token | Personal Access Token for Databricks. (only if PAT is chosen as Auth Method) |
7777
| OAuth2 Token Endpoint | URL of OAuth2 endpoint (only if OAuth2 Client Credentials Authentication is chosen as Auth Method) |
78+
| OAuth2 Scopes | Comma separated list of OAuth2 scopes. (only if OAuth2 Client Credentials Authentication is chosen as Auth Method) |
7879
| Min Interval (Default) | Min Interval default value for all queries. A lower limit for the interval. Recommended to be set to write frequency, for example `1m` if your data is written every minute. |
7980
| Max Open | The maximum number of open connections to the database. (0 = unlimited) |
8081
| Max Idle | The maximum number of idle connections to the database. (0 = no idle connections are retained) |
@@ -105,6 +106,7 @@ datasources:
105106
authenticationMethod: dsn (=PAT) | m2m | oauth2_client_credentials
106107
clientId: ...
107108
externalCredentialsUrl: ...
109+
oauthScopes: api,read
108110
timeInterval: 1m
109111
maxOpenConns: 0
110112
maxIdleConns: 0

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "mullerpeter-databricks-datasource",
33
"private": true,
4-
"version": "1.3.3",
4+
"version": "1.3.4-rc.1",
55
"description": "Databricks SQL Connector",
66
"scripts": {
77
"build": "webpack -c ./.config/webpack/webpack.config.ts --env production",

pkg/integrations/oauth2_client_credentials.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type oauth2ClientCredentials struct {
1515
clientID string
1616
clientSecret string
1717
tokenUrl string
18+
scopes []string
1819
tokenSource oauth2.TokenSource
1920
mx sync.Mutex
2021
}
@@ -35,6 +36,7 @@ func (c *oauth2ClientCredentials) Authenticate(r *http.Request) error {
3536
ClientID: c.clientID,
3637
ClientSecret: c.clientSecret,
3738
TokenURL: c.tokenUrl,
39+
Scopes: c.scopes,
3840
}
3941

4042
// Create context with 1m timeout to cancel token fetching
@@ -60,11 +62,12 @@ func (c *oauth2ClientCredentials) Authenticate(r *http.Request) error {
6062

6163
}
6264

63-
func NewOauth2ClientCredentials(clientID, clientSecret, tokenUrl string) auth.Authenticator {
65+
func NewOauth2ClientCredentials(clientID, clientSecret, tokenUrl string, scopes []string) auth.Authenticator {
6466
return &oauth2ClientCredentials{
6567
clientID: clientID,
6668
clientSecret: clientSecret,
6769
tokenUrl: tokenUrl,
70+
scopes: scopes,
6871
tokenSource: nil,
6972
mx: sync.Mutex{},
7073
}

pkg/plugin/plugin.go

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type DatasourceSettings struct {
4444
AuthenticationMethod string `json:"authenticationMethod"`
4545
ClientId string `json:"clientId"`
4646
ExternalCredentialsUrl string `json:"externalCredentialsUrl"`
47+
OAuthScopes string `json:"oauthScopes"`
4748
}
4849

4950
type ConnectionSettingsRawJson struct {
@@ -102,6 +103,7 @@ func NewSampleDatasource(_ context.Context, settings backend.DataSourceInstanceS
102103
datasourceSettings.ClientId,
103104
settings.DecryptedSecureJSONData["clientSecret"],
104105
datasourceSettings.ExternalCredentialsUrl,
106+
strings.Split(datasourceSettings.OAuthScopes, ","),
105107
)
106108
} else if datasourceSettings.AuthenticationMethod == "m2m" {
107109
authenticator = m2m.NewAuthenticatorWithScopes(

src/components/ConfigEditor/ConfigEditor.tsx

+18-8
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,24 @@ export class ConfigEditor extends PureComponent<Props, State> {
124124
/>
125125
</InlineField>
126126
{jsonData.authenticationMethod === 'oauth2_client_credentials' && (
127-
<InlineField label="OAuth2 Token Endpoint" labelWidth={30} tooltip="HTTP URL to token endpoint">
128-
<Input
129-
value={jsonData.externalCredentialsUrl || ''}
130-
placeholder="http://localhost:2020"
131-
width={40}
132-
onChange={(event: ChangeEvent<HTMLInputElement>) => this.onValueChange(event, 'externalCredentialsUrl')}
133-
/>
134-
</InlineField>
127+
<>
128+
<InlineField label="OAuth2 Token Endpoint" labelWidth={30} tooltip="HTTP URL to token endpoint">
129+
<Input
130+
value={jsonData.externalCredentialsUrl || ''}
131+
placeholder="http://localhost:2020"
132+
width={40}
133+
onChange={(event: ChangeEvent<HTMLInputElement>) => this.onValueChange(event, 'externalCredentialsUrl')}
134+
/>
135+
</InlineField>
136+
<InlineField label="OAuth2 Scopes" labelWidth={30} tooltip="Comma separated list of scopes (optional)">
137+
<Input
138+
value={jsonData.oauthScopes || ''}
139+
width={40}
140+
placeholder="api,read"
141+
onChange={(event: ChangeEvent<HTMLInputElement>) => this.onValueChange(event, 'oauthScopes')}
142+
/>
143+
</InlineField>
144+
</>
135145
)}
136146
{(jsonData.authenticationMethod === 'm2m' || jsonData.authenticationMethod === 'oauth2_client_credentials') ? (
137147
<>

src/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface DatabricksDataSourceOptions extends SQLOptions {
1010
authenticationMethod?: string;
1111
clientId?: string;
1212
externalCredentialsUrl?: string;
13+
oauthScopes?: string;
1314
retries?: string;
1415
retryBackoff?: string;
1516
maxRetryDuration?: string;

0 commit comments

Comments
 (0)