-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial HA auth (oidc) support
- Loading branch information
Showing
36 changed files
with
1,791 additions
and
655 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ runs: | |
|
||
- uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.20.x' | ||
go-version: '1.22.x' | ||
|
||
- uses: lukka/[email protected] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) 2023-2024. NetFoundry Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// | ||
// You may obtain a copy of the License at | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef ZITI_SDK_AUTH_METHOD_H | ||
#define ZITI_SDK_AUTH_METHOD_H | ||
|
||
#include "ziti_ctrl.h" | ||
|
||
enum AuthenticationMethod { | ||
LEGACY, | ||
HA | ||
}; | ||
|
||
typedef enum { | ||
ZitiAuthStateUnauthenticated, | ||
ZitiAuthStateAuthStarted, | ||
|
||
ZitiAuthStatePartiallyAuthenticated, | ||
ZitiAuthStateFullyAuthenticated, | ||
|
||
ZitiAuthImpossibleToAuthenticate, | ||
} ziti_auth_state; | ||
|
||
typedef struct ziti_ctx *ziti_context; | ||
typedef struct ziti_auth_method_s ziti_auth_method_t; | ||
typedef void (*auth_state_cb)(void *ctx, ziti_auth_state, const void *data); | ||
|
||
struct ziti_auth_method_s { | ||
enum AuthenticationMethod kind; | ||
int (*start)(ziti_auth_method_t *self, auth_state_cb cb, void *ctx); | ||
int (*force_refresh)(ziti_auth_method_t *self); | ||
int (*submit_mfa)(ziti_auth_method_t *self, const char *code); | ||
int (*stop)(ziti_auth_method_t *self); | ||
void (*free)(ziti_auth_method_t *self); | ||
}; | ||
|
||
ziti_auth_method_t *new_legacy_auth(ziti_controller *ctrl); | ||
ziti_auth_method_t *new_ha_auth(uv_loop_t *l, model_list *urls, tls_context *tls); | ||
|
||
#endif // ZITI_SDK_AUTH_METHOD_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// | ||
// Copyright NetFoundry Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
#ifndef ZITI_SDK_OIDC_H | ||
#define ZITI_SDK_OIDC_H | ||
|
||
#include <ziti/model_support.h> | ||
|
||
#include <uv.h> | ||
#include "tlsuv/http.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
typedef struct oidc_client_s oidc_client_t; | ||
typedef void (*oidc_config_cb)(oidc_client_t *, int, const char *); | ||
typedef void (*oidc_token_cb)(oidc_client_t *, int, const char *access_token); | ||
typedef void (*oidc_close_cb)(oidc_client_t *); | ||
|
||
|
||
typedef enum { | ||
oidc_native, | ||
oidc_external, | ||
} oidc_auth_mode; | ||
|
||
struct oidc_client_s { | ||
void *data; | ||
tlsuv_http_t http; | ||
|
||
const char *client_id; | ||
oidc_auth_mode mode; | ||
oidc_config_cb config_cb; | ||
oidc_token_cb token_cb; | ||
oidc_close_cb close_cb; | ||
|
||
void *config; | ||
void *tokens; | ||
uv_timer_t *timer; | ||
}; | ||
|
||
// init | ||
int oidc_client_init(uv_loop_t *loop, oidc_client_t *clt, const char *url, tls_context *tls); | ||
int oidc_client_set_url(oidc_client_t *clt, const char* url); | ||
|
||
int oidc_client_set_id(oidc_client_t *clt, const char *client_id); | ||
|
||
// configure client | ||
int oidc_client_configure(oidc_client_t *clt, oidc_config_cb); | ||
|
||
// acquire access token and start refresh cycle | ||
// oidc_token_cb will be called on first auth and on every refresh | ||
int oidc_client_start(oidc_client_t *clt, oidc_token_cb); | ||
|
||
// force token refresh ahead of normal cycle, error if called prior to oidc_client_start | ||
int oidc_client_refresh(oidc_client_t *clt); | ||
|
||
// close | ||
int oidc_client_close(oidc_client_t *clt, oidc_close_cb); | ||
|
||
#ifdef __cplusplus | ||
}; | ||
#endif | ||
|
||
#endif //ZITI_SDK_OIDC_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.