Skip to content

Commit

Permalink
identp: fix retrieving the roles claim
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolaas authored and konstlepa committed Aug 6, 2019
1 parent ee86570 commit b9a1c62
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ of the user role's claim `https://github.com/i-core/werther/claims/roles`.
```

To customize the roles claim's name you should set a value of the environment variable `WERTHER_LDAP_ROLE_CLAIM`.
Also you should map the custom name of the roles' claim to a roles's scope using the environment variable
`WERTHER_IDENTP_CLAIM_SCOPES` (the name must be [URL encoded][uri-spec-encoding]):

```bash
env WERTHER_LDAP_ROLE_CLAIM=https://my-company.com/claims/roles \
WERTHER_IDENTP_CLAIM_SCOPES=name:profile,family_name:profile,given_name:profile,email:email,https%3A%2F%2Fmy-company.com%2Fclaims%2Froles:roles \
werther
```

For more details about claims naming see [OpenID Connect Core 1.0][oidc-spec-additional-claims].

**NB** There are cases when we need to create several roles with the same name in LDAP.
Expand Down Expand Up @@ -353,3 +362,5 @@ The code in this project is licensed under [MIT license][license].
[oidc-spec-session]: https://openid.net/specs/openid-connect-session-1_0.html
[oidc-spec-front-channel-logout]: https://openid.net/specs/openid-connect-frontchannel-1_0.html
[oidc-spec-back-channel-logout]: https://openid.net/specs/openid-connect-backchannel-1_0.html

[uri-spec-encoding]: https://tools.ietf.org/html/rfc3986#section-2
5 changes: 5 additions & 0 deletions cmd/werther/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"flag"
"fmt"
"net/http"
"net/url"
"os"

"github.com/i-core/rlog"
Expand Down Expand Up @@ -58,6 +59,10 @@ func main() {
fmt.Fprintf(os.Stderr, "Invalid configuration: %s\n", err)
os.Exit(1)
}
if _, ok := cnf.Identp.ClaimScopes[url.QueryEscape(cnf.LDAP.RoleClaim)]; !ok {
fmt.Fprintf(os.Stderr, "Roles claim %q has no mapping to an OpenID Connect scope\n", cnf.LDAP.RoleClaim)
os.Exit(1)
}

logFunc := zap.NewProduction
if cnf.DevMode {
Expand Down
2 changes: 1 addition & 1 deletion internal/identp/identp.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const loginTmplName = "login.tmpl"
type Config struct {
HydraURL string `envconfig:"hydra_url" required:"true" desc:"an admin URL of ORY Hydra Server"`
SessionTTL time.Duration `envconfig:"session_ttl" default:"24h" desc:"a user session's TTL"`
ClaimScopes map[string]string `envconfig:"claim_scopes" default:"name:profile,family_name:profile,given_name:profile,email:email,http%3A%2F%2Ffithub.com%2Fi-core.ru%2Fwerther%2Fclaims%2Froles:roles" desc:"a mapping of OpenID Connect claims to scopes (all claims are URL encoded)"`
ClaimScopes map[string]string `envconfig:"claim_scopes" default:"name:profile,family_name:profile,given_name:profile,email:email,https%3A%2F%2Fgithub.com%2Fi-core%2Fwerther%2Fclaims%2Froles:roles" desc:"a mapping of OpenID Connect claims to scopes (all claims are URL encoded)"`
}

// UserManager is an interface that is used for authentication and providing user's claims.
Expand Down

0 comments on commit b9a1c62

Please sign in to comment.