update IOIDCClient interface

Naming of repair methods
This commit is contained in:
xsl
2023-06-06 13:15:04 +08:00
parent d6cf6be6d4
commit 96a41bf0db
4 changed files with 17 additions and 4 deletions

View File

@@ -1,6 +1,6 @@
# OpenID Connect SDK (client and server) for Go
[![license](https://badgen.net/github/license/xslasd/x-oidc/)](https://github.com/xslasd/x-oidc/blob/master/LICENSE)
[![release](https://badgen.net/github/release/xslasd/x-oidc/)](https://github.com/xslasd/x-oidc/releases)
[![release](https://badgen.net/github/release/xslasd/x-oidc/stable)](https://github.com/xslasd/x-oidc/releases)
## X-OIDC Introduction
The reimplemented OIDC (OpenID Connect) library, based on the zitadel/oidc library, includes both client (RP) and (OP) functionality.
It is easier to use and more extensible than the original [zitadel/oidc](https://github.com/zitadel/oidc) library. This library appears to be very useful, especially for applications that need to implement the OIDC standard.

View File

@@ -48,7 +48,7 @@ func NewOIDCClient(cfg *Config, opts ...Option) (IOIDCClient, error) {
cli := &OIDCClient{opt: opt, cfg: cfg}
discoveryConfig, err := cli.Discover()
discoveryConfig, err := cli.discover()
if err != nil {
return nil, err
}
@@ -59,6 +59,13 @@ func NewOIDCClient(cfg *Config, opts ...Option) (IOIDCClient, error) {
}
return cli, nil
}
func (o OIDCClient) JWKs() *jose.JSONWebKeySet {
return o.jwks
}
func (o OIDCClient) DiscoveryConfiguration() *model.DiscoveryConfiguration {
return o.discoveryConfig
}
func (o OIDCClient) GenerateCodeChallenge(CodeChallengeMethod string) string {
switch CodeChallengeMethod {
case constant.CodeChallengeMethodPlain:
@@ -304,7 +311,7 @@ func (o OIDCClient) SendHttpRequest(url string, method string, header map[string
respBody, err := io.ReadAll(res.Body)
return respBody, err
}
func (o OIDCClient) Discover() (*model.DiscoveryConfiguration, error) {
func (o OIDCClient) discover() (*model.DiscoveryConfiguration, error) {
wellKnown := strings.TrimSuffix(o.cfg.Issuer, "/") + constant.DiscoveryEndpoint
res, err := o.SendHttpRequest(wellKnown, constant.HttpMethodGet, nil, nil)
if err != nil {

View File

@@ -1,6 +1,9 @@
package rp
import "github.com/xslasd/x-oidc/model"
import (
"github.com/go-jose/go-jose/v3"
"github.com/xslasd/x-oidc/model"
)
type Config struct {
ClientID string
@@ -60,4 +63,7 @@ type IOIDCClient interface {
IntrospectToken(req *IntrospectionReq) (*model.IntrospectionModel, error)
RevokeToken(req *RevokeTokenReq) (bool, error)
ValidateIDToken(idToken string) (*model.IDTokenClaims, error)
DiscoveryConfiguration() *model.DiscoveryConfiguration
JWKs() *jose.JSONWebKeySet
SendHttpRequest(url string, method string, header map[string]string, body map[string]string) ([]byte, error)
}