Skip to content

Commit d1e0823

Browse files
authored
Merge pull request #2522 from keboola/hosan/AJDA-2273
Add JumpCloud authentication provider support
2 parents 0c97807 + ad5deab commit d1e0823

3 files changed

Lines changed: 113 additions & 4 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package provider
2+
3+
import proxyOptions "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options"
4+
5+
type JumpCloud struct {
6+
OIDC
7+
}
8+
9+
func (v JumpCloud) ProxyProviderOptions() (proxyOptions.Provider, error) {
10+
p, err := v.OIDC.ProxyProviderOptions()
11+
if err != nil {
12+
return proxyOptions.Provider{}, err
13+
}
14+
15+
p.LoginURLParameters = []proxyOptions.LoginURLParameter{
16+
{
17+
// JumpCloud doesn't support "select_account" prompt
18+
// Returns: "Used unknown value '[select_account]' for prompt parameter"
19+
Name: "prompt",
20+
Default: []string{"login"},
21+
},
22+
}
23+
24+
return p, nil
25+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package provider
2+
3+
import (
4+
"encoding/json"
5+
"testing"
6+
7+
proxyOptions "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options"
8+
"github.com/stretchr/testify/assert"
9+
"github.com/stretchr/testify/require"
10+
)
11+
12+
func TestJumpCloud(t *testing.T) {
13+
t.Parallel()
14+
15+
// Mock part of the API response
16+
providerJSON := `
17+
{
18+
"id": "my-id",
19+
"name": "My Name",
20+
"type": "jumpcloud",
21+
"clientId": "6779ef20e75817b79602",
22+
"clientSecret": "f2a1ed52710d4533bde25be6da03b6e3",
23+
"issuerUrl": "https://www.linkedin.com",
24+
"logoutUrl": "https://www.linkedin.com/oidc/logout",
25+
"allowedRoles": ["admin"]
26+
}
27+
`
28+
29+
// Unmarshal, detect the target struct
30+
var providers Providers
31+
require.NoError(t, json.Unmarshal([]byte("["+providerJSON+"]"), &providers))
32+
require.Len(t, providers, 1)
33+
34+
// Decoded content
35+
provider := providers[0]
36+
assert.Equal(t, JumpCloud{
37+
OIDC: OIDC{
38+
Base: Base{
39+
Info: Info{
40+
ID: "my-id",
41+
Name: "My Name",
42+
Type: TypeJumpCloud,
43+
},
44+
},
45+
ClientID: "6779ef20e75817b79602",
46+
ClientSecret: "f2a1ed52710d4533bde25be6da03b6e3",
47+
IssuerURL: "https://www.linkedin.com",
48+
LogoutURL: "https://www.linkedin.com/oidc/logout",
49+
AllowedRoles: &[]string{"admin"},
50+
},
51+
}, provider)
52+
53+
// OAuth2Proxy configuration
54+
oAuth2ProxyProvider, ok := provider.(JumpCloud)
55+
require.True(t, ok)
56+
proxyOpts, err := oAuth2ProxyProvider.ProxyProviderOptions()
57+
require.NoError(t, err)
58+
assert.Equal(t, proxyOptions.Provider{
59+
ID: "my-id",
60+
Type: "oidc",
61+
Name: "My Name",
62+
CodeChallengeMethod: "S256",
63+
ClientID: "6779ef20e75817b79602",
64+
ClientSecret: "f2a1ed52710d4533bde25be6da03b6e3",
65+
BackendLogoutURL: "https://www.linkedin.com/oidc/logout",
66+
AllowedGroups: []string{"admin"},
67+
OIDCConfig: proxyOptions.OIDCOptions{
68+
IssuerURL: "https://www.linkedin.com",
69+
EmailClaim: "email",
70+
GroupsClaim: "groups",
71+
AudienceClaims: []string{"aud"},
72+
UserIDClaim: "email",
73+
},
74+
LoginURLParameters: []proxyOptions.LoginURLParameter{
75+
{
76+
Name: "prompt",
77+
Default: []string{"login"},
78+
},
79+
},
80+
}, proxyOpts)
81+
}

internal/pkg/service/appsproxy/dataapps/auth/provider/provider.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ import (
1111
)
1212

1313
const (
14-
TypeOIDC Type = "oidc"
15-
TypeGitLab Type = "gitlab"
16-
TypeGitHub Type = "github"
17-
TypeBasic Type = "password"
14+
TypeOIDC Type = "oidc"
15+
TypeGitLab Type = "gitlab"
16+
TypeGitHub Type = "github"
17+
TypeBasic Type = "password"
18+
TypeJumpCloud Type = "jumpcloud"
1819
)
1920

2021
// ID is unique identifier of the authentication provider inside a data app.
@@ -53,6 +54,8 @@ func (t Type) new() (Provider, error) {
5354
return GitHub{}, nil
5455
case TypeBasic:
5556
return Basic{}, nil
57+
case TypeJumpCloud:
58+
return JumpCloud{}, nil
5659
default:
5760
return nil, errors.Errorf(`unexpected type of data app auth provider "%v"`, t)
5861
}

0 commit comments

Comments
 (0)