github.com/IBM-Cloud/bluemix-go@v0.0.0-20240314082800-4e02a69b84b2/api/iam/iamv1/identity.go (about)

     1  package iamv1
     2  
     3  import (
     4  	"github.com/IBM-Cloud/bluemix-go/client"
     5  )
     6  
     7  type AccountInfo struct {
     8  	Bss string `json:"bss"`
     9  	Ims string `json:"ims"`
    10  }
    11  
    12  type UserInfo struct {
    13  	Active     bool        `json:"active"`
    14  	RealmID    string      `json:"realmId"`
    15  	Identifier string      `json:"identifier"`
    16  	IamID      string      `json:"iam_id"`
    17  	GivenName  string      `json:"given_name"`
    18  	FamilyName string      `json:"family_name"`
    19  	Name       string      `json:"name"`
    20  	Email      string      `json:"email"`
    21  	Sub        string      `json:"sub"`
    22  	Account    AccountInfo `json:"account"`
    23  	Iat        int         `json:"iat"`
    24  	Exp        int         `json:"exp"`
    25  	Iss        string      `json:"iss"`
    26  	GrantType  string      `json:"grant_type"`
    27  	ClientID   string      `json:"client_id"`
    28  	Scope      string      `json:"scope"`
    29  	Acr        int         `json:"acr"`
    30  	Amr        []string    `json:"amr"`
    31  }
    32  
    33  type Identity interface {
    34  	UserInfo() (*UserInfo, error)
    35  }
    36  
    37  type identity struct {
    38  	client *client.Client
    39  }
    40  
    41  func NewIdentity(c *client.Client) Identity {
    42  	return &identity{
    43  		client: c,
    44  	}
    45  }
    46  
    47  func (r *identity) UserInfo() (*UserInfo, error) {
    48  	userInfo := UserInfo{}
    49  	_, err := r.client.Get("/identity/userinfo", &userInfo)
    50  	if err != nil {
    51  		return nil, err
    52  	}
    53  	return &userInfo, nil
    54  }