Skip to content

Commit 5d89891

Browse files
committed
oauth2 client credentials auth style improvement
1 parent 17f354d commit 5d89891

File tree

5 files changed

+44
-7
lines changed

5 files changed

+44
-7
lines changed

.changeset/curvy-waves-switch.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'grafana-infinity-datasource': minor
3+
---
4+
5+
🚀 **OAuth2**: Added ability to set auth style in client credentials

pkg/infinity/oauth.go

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func ApplyOAuthClientCredentials(httpClient *http.Client, settings models.Infini
2323
TokenURL: settings.OAuth2Settings.TokenURL,
2424
Scopes: []string{},
2525
EndpointParams: url.Values{},
26+
AuthStyle: settings.OAuth2Settings.AuthStyle,
2627
}
2728
for _, scope := range settings.OAuth2Settings.Scopes {
2829
if scope != "" {

pkg/models/settings.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"strings"
99

1010
"github.com/grafana/grafana-plugin-sdk-go/backend"
11+
"golang.org/x/oauth2"
1112
)
1213

1314
const (
@@ -33,13 +34,14 @@ const (
3334
)
3435

3536
type OAuth2Settings struct {
36-
OAuth2Type string `json:"oauth2_type,omitempty"`
37-
ClientID string `json:"client_id,omitempty"`
38-
TokenURL string `json:"token_url,omitempty"`
39-
Email string `json:"email,omitempty"`
40-
PrivateKeyID string `json:"private_key_id,omitempty"`
41-
Subject string `json:"subject,omitempty"`
42-
Scopes []string `json:"scopes,omitempty"`
37+
OAuth2Type string `json:"oauth2_type,omitempty"`
38+
ClientID string `json:"client_id,omitempty"`
39+
TokenURL string `json:"token_url,omitempty"`
40+
Email string `json:"email,omitempty"`
41+
PrivateKeyID string `json:"private_key_id,omitempty"`
42+
Subject string `json:"subject,omitempty"`
43+
Scopes []string `json:"scopes,omitempty"`
44+
AuthStyle oauth2.AuthStyle `json:"authStyle,omitempty"`
4345
ClientSecret string
4446
PrivateKey string
4547
EndpointParams map[string]string

src/editors/config/OAuthInput.tsx

+28
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,34 @@ export const OAuthInputsEditor = (props: DataSourcePluginOptionsEditorProps<Infi
4444
</div>
4545
{oauth2.oauth2_type === 'client_credentials' && (
4646
<>
47+
<div className="gf-form">
48+
<InlineFormLabel
49+
width={10}
50+
tooltip={
51+
<>
52+
{`AuthStyleAutoDetect means to auto-detect which authentication style the provider wants by trying both ways and caching the successful way for the future.`}
53+
<br />
54+
<br />
55+
{`AuthStyleInParams sends the "client_id" and "client_secret" in the POST body as application/x-www-form-urlencoded parameters.`}
56+
<br />
57+
<br />
58+
{`AuthStyleInHeader sends the client_id and client_password using HTTP Basic Authorization. This is an optional style described in the OAuth2 RFC 6749 section 2.3.1.`}
59+
</>
60+
}
61+
{...{ interactive: true }}
62+
>
63+
Auth Style
64+
</InlineFormLabel>
65+
<RadioButtonGroup
66+
options={[
67+
{ value: 0, label: 'Auto' },
68+
{ value: 1, label: 'In Params' },
69+
{ value: 2, label: 'In Header' },
70+
]}
71+
onChange={(v) => onOAuth2PropsChange('authStyle', v || 0)}
72+
value={oauth2.authStyle || 0}
73+
></RadioButtonGroup>
74+
</div>
4775
<div className="gf-form">
4876
<InlineFormLabel width={10}>Client ID</InlineFormLabel>
4977
<Input onChange={(v) => onOAuth2PropsChange('client_id', v.currentTarget.value)} value={oauth2.client_id} width={30} placeholder={'Client ID'} />

src/types/config.types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export type OAuth2Props = {
1818
subject?: string;
1919
token_url?: string;
2020
scopes?: string[];
21+
authStyle?: number;
2122
};
2223
export type AWSAuthProps = {
2324
authType?: 'keys';

0 commit comments

Comments
 (0)