Skip to content

Instantly share code, notes, and snippets.

@aslafy-z
Last active July 11, 2024 10:49
Show Gist options
  • Save aslafy-z/c7e6cc1e2efb15b33fe497e4adbbf6f5 to your computer and use it in GitHub Desktop.
Save aslafy-z/c7e6cc1e2efb15b33fe497e4adbbf6f5 to your computer and use it in GitHub Desktop.

Dex: encode Oauth2Client CRD name

Source dexidp/dex#1606 (comment)

Dex OAuth2Client CRD metadata.name field should match spec.id and spec.name but needs a special encoding.

Generate it with:

wget https://gist.github.com/aslafy-z/c7e6cc1e2efb15b33fe497e4adbbf6f5/raw/dex-encode-crd-name.go
go run dex-encode-crd-name.go "some-client"

Then, feed it to your OAuth2Client CRD as ${CLIENT_ID_ENCODED}:

apiVersion: dex.coreos.com/v1
kind: OAuth2Client
metadata:
  name: ${CLIENT_ID_ENCODED}
id: some-client
name: some-client
secret: <some-secret>
redirectURIs:
- https://foo
package main
import (
"encoding/base32"
"fmt"
"hash/fnv"
"os"
"strings"
)
var encoding = base32.NewEncoding("abcdefghijklmnopqrstuvwxyz234567")
func main() {
if len(os.Args) < 2 {
fmt.Printf("Usage: %s <string>\n", os.Args[0])
os.Exit(1)
}
toDecodeString := []byte(os.Args[1])
encodedString := strings.TrimRight(encoding.EncodeToString(fnv.New64().Sum(toDecodeString)), "=")
fmt.Println(encodedString)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment