| 1 |
package oauth2 |
| 2 |
|
| 3 |
import ( |
| 4 |
"context" |
| 5 |
"log/slog" |
| 6 |
|
| 7 |
"cel.dev/cel-go/cel" |
| 8 |
types2 "github.com/jkroepke/openvpn-auth-oauth2/v2/internal/config" |
| 9 |
"github.com/jkroepke/openvpn-auth-oauth2/v2/internal/crypto" |
| 10 |
"github.com/jkroepke/openvpn-auth-oauth2/v2/internal/oauth2/idtoken" |
| 11 |
"github.com/jkroepke/openvpn-auth-oauth2/v2/internal/oauth2/types" |
| 12 |
"github.com/jkroepke/openvpn-auth-oauth2/v2/internal/state" |
| 13 |
"github.com/jkroepke/openvpn-auth-oauth2/v2/internal/tokenstorage" |
| 14 |
"github.com/zitadel/oidc/v3/pkg/client/rp" |
| 15 |
) |
| 16 |
|
| 17 |
type Client struct { |
| 18 |
relyingParty rp.RelyingParty |
| 19 |
openvpn openvpnManagementClient |
| 20 |
storage tokenstorage.Storage |
| 21 |
provider Provider |
| 22 |
validationCELPrg cel.Program |
| 23 |
usernameCELPrg cel.Program |
| 24 |
configsCELPrg cel.Program |
| 25 |
logger *slog.Logger |
| 26 |
stateCrypto *crypto.Cipher |
| 27 |
conf *types2.Config |
| 28 |
authorizeParams []rp.URLParamOpt |
| 29 |
} |
| 30 |
|
| 31 |
type Provider interface { |
| 32 |
CheckUser(ctx context.Context, session state.State, user types.UserInfo, tokens *idtoken.IDToken) error |
| 33 |
GetProviderConfig() (types.ProviderConfig, error) |
| 34 |
GetName() string |
| 35 |
GetRefreshToken(tokens *idtoken.IDToken) (string, error) |
| 36 |
GetUser(ctx context.Context, logger *slog.Logger, tokens *idtoken.IDToken, userinfo *types.UserInfo) (types.UserInfo, error) |
| 37 |
|
| 38 |
// Refresh initiates a non-interactive authentication against the sso provider. |
| 39 |
Refresh(ctx context.Context, relyingParty rp.RelyingParty, refreshToken string) (*idtoken.IDToken, error) |
| 40 |
RevokeRefreshToken(ctx context.Context, relyingParty rp.RelyingParty, refreshToken string) error |
| 41 |
} |
| 42 |
|
| 43 |
// clientConfigToken is used to store additional information on the client side. |
| 44 |
type clientConfigToken struct { |
| 45 |
Username string `json:"username,omitempty"` |
| 46 |
EncryptedOAuth2State state.EncryptedState `json:"state,omitempty"` |
| 47 |
Profiles []string `json:"profiles,omitempty"` |
| 48 |
} |