Categorygithub.com/lpar/ibmoidc
modulepackage
1.2.1
Repository: https://github.com/lpar/ibmoidc.git
Documentation: pkg.go.dev

# README

OpenID Connect for IBMid

This is support code for authenticating using IBM's OpenID Connect authentication servers, in particular IBMid.

The OpenID Connect parameters for IBMid are provided in the call to NewIBMidAuthenticator:

  1. The client ID, given to you during the enrollment process
  2. The client secret, ditto
  3. The callback URL

Example usage:

ibmid := ibmoidc.NewIBMidAuthenticator(myClientID, myClientSecret, myCallbackURL)

http.Handle("/login", ibmid.BeginLogin())
http.Handle("/openid/code", ibmid.CompleteLogin(myauthhandler))

where the callback URL is https://www.example.com/openid/code on your web app.

The http.Handler myauthhandler can then do:

token, ok := ibmoidc.TokenFromRequest(r) // r is the http.Request

The jwt.Token in token will contain the the authenticated information from IBMid. At that point it's up to you to work out some way to persist it via a session, cookies, or whatever.

It's also up to you to access and unpack the ext parameter from the JWT, which contains JSON you can deserialize in order to obtain the BlueGroups information.

Here's an example of how you might turn the token into a User object:

type User struct {
  Name       string
  Email      string
  Company    string
  BlueGroups []string
}

func getString(tok *jwt.Token, key string) string {
  x, ok := tok.Get(key)
  if !ok {
    return ""
  }
  switch v := x.(type) {
  case string:
    return v
  default:
    return ""
  }
}

func NewUser(tok *jwt.Token) *User {
  type Ext struct {
    BlueGroups []string `json:"blueGroups"`
    Company    string   `json:"company"`
  }
  user := &User{}
  extjson, ok := tok.Get("ext")
  if ok {
    extstr := extjson.(string)
    ext := Ext{}
    err := json.Unmarshal([]byte(extstr), &ext)
    if err == nil {
      user.Company = ext.Company
      user.BlueGroups = ext.BlueGroups
    }
  }
  user.Email = getString(tok, "email")
  user.Name = getString(tok, "name")
  return user
}

Copyright © IBM Corporation 2016-2019.

# Functions

MakeCSRFcookie turns a string generated by MakeCSRFtoken into a CSRF cookie.
MakeCSRFtoken makes a random 32-character string for use as a CSRF token.
NewIntranetAuthenticator creates an Authenticator object for processing IBMid authentication server responses.
NewIntranetAuthenticator creates an Authenticator object for processing intranet w3ID authentication server responses.
NewIntranetStagingAuthenticator creates an Authenticator object for processing intranet w3ID authentication server responses from the staging server.
ReadCSRFcookie gets the token from the CSRF cookie, if found.
RequestWithToken adds a token to the http request, using a private context key.
TokenFromRequest obtains the authenticated token from the request's context, where it was stored earlier by RequestWithToken.

# Variables

IBMidEndpoint is the Endpoint for IBMid authentication.
No description provided by the author
IBMw3idEndpoint is the Endpoint for IBM w3ID authentication.
IBMw3idPublicKey is the rsa.PublicKey to use to verify the signature on an id_token value returned from IBMw3idEndpoint.TokenURL.
IBMw3idStagingEndpoint is the endpoint for testing IBM w3ID authentication.
No description provided by the author
IBMw3idEndpoint is the TAP pilot endpoint for IBM w3ID authentication.
IBMw3idPublicKey is the rsa.PublicKey to use to verify the signature on an id_token value returned from IBMw3idTapEndpoint.TokenURL.

# Structs

Authenticator is an object for processing IBM authentication responses.