Added more to refresh token flow implementation

This commit is contained in:
David J. Allen 2024-03-18 16:03:37 -06:00
parent 555d172ba6
commit c25e3e2e1e
No known key found for this signature in database
GPG key ID: 717C593FF60A2ACC
4 changed files with 127 additions and 46 deletions

View file

@ -20,6 +20,7 @@ type IdentityProvider struct {
}
type Endpoints struct {
Config string `db:"config_endpoint" json:"config_endpoint" yaml:"config"`
Authorization string `db:"authorization_endpoint" json:"authorization_endpoint" yaml:"authorization"`
Token string `db:"token_endpoint" json:"token_endpoint" yaml:"token"`
Revocation string `db:"revocation_endpoint" json:"revocation_endpoint" yaml:"revocation"`
@ -109,6 +110,30 @@ func (p *IdentityProvider) LoadServerConfig(path string) error {
return nil
}
func (p *IdentityProvider) FetchServerConfig() error {
// make a request to a server's openid-configuration
req, err := http.NewRequest(http.MethodGet, p.Issuer+"/.well-known/openid-configuration", bytes.NewBuffer([]byte{}))
if err != nil {
return fmt.Errorf("failed to create a new request: %v", err)
}
client := &http.Client{} // temp client to get info and not used in flow
res, err := client.Do(req)
if err != nil {
return fmt.Errorf("failed to do request: %v", err)
}
body, err := io.ReadAll(res.Body)
if err != nil {
return fmt.Errorf("failed to read response body: %v", err)
}
err = p.ParseServerConfig(body)
if err != nil {
return fmt.Errorf("failed to parse server config: %v", err)
}
return nil
}
func FetchServerConfig(issuer string) (*IdentityProvider, error) {
// make a request to a server's openid-configuration
req, err := http.NewRequest(http.MethodGet, issuer+"/.well-known/openid-configuration", bytes.NewBuffer([]byte{}))