Skip to content

Commit

Permalink
Fixed some minor issues
Browse files Browse the repository at this point in the history
  • Loading branch information
davidallendj committed Apr 30, 2024
1 parent 7022801 commit e929fac
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions internal/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func NewServerWithConfig(conf *Config) *server.Server {
Host: conf.Server.Issuer.Host,
Port: conf.Server.Issuer.Port,
Endpoints: conf.Server.Issuer.Endpoints,
Clients: conf.Server.Issuer.Clients,
},
}
return server
Expand Down
1 change: 0 additions & 1 deletion internal/oidc/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ func UpdateEndpoints(eps *Endpoints, other *Endpoints) {
if ep != nil {
if *ep == "" {
*ep = s
fmt.Printf("updated %s\n", s)
}
}
}
Expand Down
14 changes: 9 additions & 5 deletions internal/server/idp.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ func (s *Server) StartIdentityProvider() error {

// update endpoints that have values set
defaultEps := oidc.Endpoints{
Authorization: "http://" + s.Addr + "/oauth/authorize",
Token: "http://" + s.Addr + "/oauth/token",
Authorization: "http://" + s.Addr + "/oauth2/authorize",
Token: "http://" + s.Addr + "/oauth2/token",
JwksUri: "http://" + s.Addr + "/.well-known/jwks.json",
}
oidc.UpdateEndpoints(&s.Issuer.Endpoints, &defaultEps)
Expand Down Expand Up @@ -266,9 +266,13 @@ func (s *Server) StartIdentityProvider() error {
return
}

// check that we're using the default registered client
if clientId != "ochami" {
fmt.Printf("invalid client\n")
// find a valid client
index := slices.IndexFunc(s.Issuer.Clients, func(c RegisteredClient) bool {
fmt.Printf("%s ? %s\n", c.Id, clientId)
return c.Id == clientId
})
if index < 0 {
fmt.Printf("no valid client found")
return
}

Expand Down
9 changes: 5 additions & 4 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (s *Server) StartLogin(clients []oauth.Client, params ServerParams) error {

// make the login page SSO buttons and authorization URLs to write to stdout
buttons := ""
fmt.Printf("Login with external identity providers: \n")
fmt.Printf("Login with an identity provider: \n")
for i, client := range clients {
// fetch provider configuration before adding button
p, err := oidc.FetchServerConfig(client.Provider.Issuer)
Expand All @@ -74,8 +74,7 @@ func (s *Server) StartLogin(clients []oauth.Client, params ServerParams) error {

clients[i].Provider = *p
buttons += makeButton(fmt.Sprintf("/login?sso=%s", client.Id), client.Name)
url := client.BuildAuthorizationUrl(s.State)
fmt.Printf("\t%s\n", url)
fmt.Printf("\t%s: /login?sso=%s\n", client.Name, client.Id)
}

var code string
Expand Down Expand Up @@ -115,7 +114,9 @@ func (s *Server) StartLogin(clients []oauth.Client, params ServerParams) error {
client = &clients[index]

url := client.BuildAuthorizationUrl(s.State)
fmt.Printf("Redirect URL: %s\n", url)
if params.Verbose {
fmt.Printf("Redirect URL: %s\n", url)
}
http.Redirect(w, r, url, http.StatusFound)
return
}
Expand Down

0 comments on commit e929fac

Please sign in to comment.