Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: get auth providers in client sdk #1726

Merged
merged 2 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions config/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,14 @@ func (c *AuthConfig) AddOidcProvider(name string, issuerUrl string, clientId str
if strings.HasPrefix(err.Message, fmt.Sprintf("auth.providers.%d.name", newProviderIndex)) {
// This function allows the adding of internal auth providers which can start with 'keel_'
if !strings.Contains(err.Message, "Cannot start with 'keel_'") {
return fmt.Errorf(err.Message)
return err
}
}
if strings.HasPrefix(err.Message, fmt.Sprintf("auth.providers.%d.issuerUrl", newProviderIndex)) {
return fmt.Errorf(err.Message)
return err
}
if strings.HasPrefix(err.Message, fmt.Sprintf("auth.providers.%d.clientId", newProviderIndex)) {
return fmt.Errorf(err.Message)
return err
}
}

Expand Down
18 changes: 18 additions & 0 deletions integration/testdata/client_auth/keelconfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
auth:
providers:
- type: oidc
name: myOidcProvider
issuerUrl: "https://auth.example.com/"
clientId: foo_1
- type: google
name: googleProvider
clientId: foo_3
- type: slack
name: slackProvider
clientId: foo_4
- type: facebook
name: facebookProvider
clientId: foo_5
- type: gitlab
name: Gitlab_Provider
clientId: foo_6
52 changes: 52 additions & 0 deletions integration/testdata/client_auth/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,55 @@ test("authentication - not authenticated and no permissions", async () => {
expect(response.data?.results).toHaveLength(1);
expect(response.error).toBeUndefined();
});

test("authentication - get providers", async () => {
const provs = await client.auth.providers();
console.log(provs);

expect(provs.data?.[0]).toEqual({
name: "myOidcProvider",
type: "oidc",
authorizeUrl:
process.env.KEEL_TESTING_AUTH_API_URL + "/authorize/myoidcprovider",
callbackUrl:
process.env.KEEL_TESTING_AUTH_API_URL + "/callback/myoidcprovider",
});

expect(provs.data?.[1]).toEqual({
name: "googleProvider",
type: "google",
authorizeUrl:
process.env.KEEL_TESTING_AUTH_API_URL + "/authorize/googleprovider",
callbackUrl:
process.env.KEEL_TESTING_AUTH_API_URL + "/callback/googleprovider",
});

expect(provs.data?.[2]).toEqual({
name: "slackProvider",
type: "slack",
authorizeUrl:
process.env.KEEL_TESTING_AUTH_API_URL + "/authorize/slackprovider",
callbackUrl:
process.env.KEEL_TESTING_AUTH_API_URL + "/callback/slackprovider",
});

expect(provs.data?.[3]).toEqual({
name: "facebookProvider",
type: "facebook",
authorizeUrl:
process.env.KEEL_TESTING_AUTH_API_URL + "/authorize/facebookprovider",
callbackUrl:
process.env.KEEL_TESTING_AUTH_API_URL + "/callback/facebookprovider",
});

expect(provs.data?.[4]).toEqual({
name: "Gitlab_Provider",
type: "gitlab",
authorizeUrl:
process.env.KEEL_TESTING_AUTH_API_URL + "/authorize/gitlab_provider",
callbackUrl:
process.env.KEEL_TESTING_AUTH_API_URL + "/callback/gitlab_provider",
});

expect(provs.data?.length).toEqual(5);
});
2 changes: 1 addition & 1 deletion node/templates/client/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export class Core {
});

if (result.ok) {
return await result.json();
return { data: await result.json() };
} else {
return {
error: {
Expand Down
10 changes: 2 additions & 8 deletions runtime/apis/authapi/authorize_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,19 +159,13 @@ func CallbackHandler(schema *proto.Schema) common.HandlerFunc {
return common.InternalServerErrorResponse(ctx, err)
}

// Establishes new OIDC provider. This will call the providers discovery endpoint
oidcProvider, err := oidc.NewProvider(ctx, provider.IssuerUrl)
if err != nil {
return common.InternalServerErrorResponse(ctx, err)
}

// ClientSecret is required for token exchange
oauthConfig := &oauth2.Config{
ClientID: provider.ClientId,
ClientSecret: secret,
Endpoint: oauth2.Endpoint{
AuthURL: oidcProvider.Endpoint().AuthURL,
TokenURL: oidcProvider.Endpoint().TokenURL,
AuthURL: oidcProv.Endpoint().AuthURL,
TokenURL: oidcProv.Endpoint().TokenURL,
},
RedirectURL: callbackUrl.String(),
}
Expand Down
3 changes: 0 additions & 3 deletions runtime/apis/authapi/providers_endpoint.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package authapi

import (
"fmt"
"net/http"
"strings"

Expand All @@ -25,8 +24,6 @@ func ProvidersHandler(schema *proto.Schema) common.HandlerFunc {

config, err := runtimectx.GetOAuthConfig(ctx)
if err != nil {
fmt.Println(err)

return common.InternalServerErrorResponse(ctx, err)
}

Expand Down
2 changes: 2 additions & 0 deletions testing/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ func Run(ctx context.Context, opts *RunnerOpts) error {
os.Setenv(key, value)
}

os.Setenv("KEEL_API_URL", fmt.Sprintf("http://localhost:%s", runtimePort))

// Server to handle receiving HTTP requests from the ActionExecutor, JobExecutor and SubscriberExecutor.
runtimeServer := http.Server{
Addr: fmt.Sprintf(":%s", runtimePort),
Expand Down
Loading