Skip to content

Identity Wrapper is a GO component which provides ERPLY Identity Service endpoints for other GO projects.

License

Notifications You must be signed in to change notification settings

erply/identity-wrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Identity Wrapper

Identity Wrapper is a GO component which provides ERPLY Identity Service endpoints for other GO projects.

For example:

  • login with credentials
  • launch apps
  • get JWT
  • revoke JWT
  • verify JWT.
  • etc.

Requirements

  • go 1.12+

Functions

Import package

import (
	"github.com/erply/identity-wrapper/Identity"
)

How to setup?

Production Env
  • host is https://id-api.erply.com/
  • apiWorkers - Default value 1
  • maxIdleConnections - Default value 1
  • maxConnections - Default value 1
Sandbox Env
  • host is https://id-api-sb.erply.com/
  • apiWorkers - Default value 1
  • maxIdleConnections - Default value 1
  • maxConnections - Default value 1

How to use?

Init Identity API

Init

identityAPI := Identity.SetupAPI(host, apiWorkers, maxIdleConnections, maxConnections)

identityAPI.Init()

*Note: apiWorkers, maxIdleConnections, maxConnections are variadic input parameters. SetupAPI function can be called like:

//Option 1

identityAPI := Identity.SetupAPI(host)	

//Option 2

identityAPI := Identity.SetupAPI(host, apiWorkers)	

//Option 3

identityAPI := Identity.SetupAPI(host, apiWorkers, maxIdleConnections)
LoginWithCredentials()

LoginWithCredentials()

Login to Identity Launchpad with email and password to get JWT. Launchpad JWT is in limited permissions. Check permissions from here https://jwt.io

login, err := identityAPI.LoginWithCredentials("[email protected]", "ExamplePass12")

jwt := login.Result.JWT
companyID := login.Result.DefaultCompanyId

// For other companies IDs you will get if you use func GetUserConfirmedCompanies()
GetApplications()

GetApplications()

Get list of all applications.

apps, err := identityAPI.GetApplications(jwt)
	
GetAccountAccess()

GetAccountAccess()

Get list of applications IDs where user account has access. Also, returns company based AccountID to launch apps.

access, err := identityAPI.GetAccountAccess(jwt, companyID)
accountID := access.Result.AccountID
	
GetUserConfirmedCompanies()

GetUserConfirmedCompanies()

Get list of companies where user has access.

companies, err := identityAPI.GetUserConfirmedCompanies(jwt)
	
LaunchApp()

LaunchApp()

Use JWT and and your selected AccountID to launch app and get launchCode.

launch, err := identityAPI.LaunchApp(jwt, accountID)
launchCode := launch.Result.LaunchCode
	
GetJWT()

GetJWT()

Get JWT by launchCode. LunchCode is a hash which expires after 30 sec. Returns JWT with all permissions you have. JWT lives in 24 hours.

getJWT, err := identityAPI.GetJWT(launchCode)
appJWT := getJWT.Result.JWT
	
GetSessionID()

GetSessionID()

  • GetSessionID by JWT. It returns short session token for Builder applications and Service Engine endpoints.
  • Use this token in headers.
    • JSESSIONID - if using Builder apps.
    • API_KEY - if using Service Engine endpoints.
getSession, _ := identityAPI.GetSessionID(appJWT)
sessionID := getSession.Result.Session
RevokeJWT()

RevokeJWT()

It revokes persistence token which makes token unusable. Persistence token is inside of JWT.

revoke, err := identityAPI.RevokeJWT(jwt)
	
VerifyJWT()

VerifyJWT()

Verify persistence token by sending JWT. Returns (boolean) TRUE if it's valid and FALSE if expired or not exist.

verify, err := identityAPI.VerifyJWT(jwt)
	

Use public key to verify JWT

Production Env

https://apps.erply.com/jwt/pubkey.pem

Sandbox Env

https://apps-sb.erply.com/jwt/pubkey.pem

Author

Changelog

1.1.1
1.1.1
  • Changed module to github.com
1.1.0
1.1.0
  • [IS-19] New endpoint getSessionID.
1.0.2
1.0.2
  • security update: better config for net/http
1.0.1
1.0.1
  • more pointers, optional parameters for SetupAPI func
1.0.0
1.0.0
  • [IS-19] Updated documentation and ready to use.
0.1.0
0.1.0
  • [IS-19] Initial implementation.

About

Identity Wrapper is a GO component which provides ERPLY Identity Service endpoints for other GO projects.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages