8000
Skip to content

Latest commit

 

History

23 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

license Go Report Card Go Reference

groupcache_oidcpismo

https://github.com/udhos/groupcache_oidcpismo implements the OIDC flow for Pismo while cacheing tokens with distributed cache groupcache.

See:

https://developers.pismo.io/pismo-docs/docs/authentication-with-openid#generate-your-jwt

https://developers.pismo.io/pismo-docs/reference/post-passport-v1-oauth2-token-1

Synopsis

Create an HTTP client that can automatically obtain and refresh OIDC tokens for Pismo, while managing cached tokens in distributed cache groupcache.

NOTE: Do not forget to add the required header x-account-id.

privKeyPem, errRead := os.ReadFile("key-priv.pem")

privKey, errParse := jwt.ParseRSAPrivateKeyFromPEM(privKeyPem)

opt := oidcpismo.Options{
    TokenURL: "https://sandbox.pismolabs.io/passport/v1/oauth2/token",
    Client:   http.DefaultClient,
    PrivKey:  privKey,

    TenantID:     "tenant-id",
    Pismo:        map[string]any{
        "group": "pismo-v1:some-samplegroup:rw",
    },
    CustomClaims: map[string]any{
        "custom1":     "someValue",
        "userexample": "user@user.com",
    },
    Issuer:   "issuer",
    Subject:  "subject",
    Audience: "audience",
    Expire:   time.Hour,
}

options := oidc.Options{
    Options:             opt,
    GroupcacheWorkspace: groupcacheWorkspace,
}

client := oidc.New(options)

req, errReq := http.NewRequestWithContext(context.TODO(), "GET",
    "http://example.com", nil)

req.Header.Add("x-account-id", "some-account-id")

resp, errDo = client.Do(req)

Example

See cmd/groupcache-oidcpismo-client-example/main.go for a complete example.

Testing

Start the token server oidcpismo-server from project https://github.com/udhos/oidcpismo:

oidcpismo-server

Run the example client:

groupcache-oidcpismo-client-example

About

groupcache_oidcpismo implements the OIDC flow for Pismo while cacheing tokens with distributed cache groupcache.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages

0