Integration and Usage

In this example we use go-chi to build the RESTful service. You can view the full code here, and find the SDK here.

Initialization

Add the following in the go.mod file.

require (	...	github.com/ontology-tech/ontlogin-sdk-go latest)

Add API Methods

Import the methods in the main.go file.

  • requestChallenge: Returns the challenge from the server

  • submitChallenge : Passes the signed challenge and VP (if requested by the server)

package main
import (	
        "log"
        "net/http"
        "github.com/go-chi/chi/v5"	
        "github.com/go-chi/chi/v5/middleware"	
        "github.com/go-chi/cors"
        "ontlogin-sample/auth"	
        "ontlogin-sample/service"
)

Initialize the service, perform cross-origin resource sharing checks and define API methods.

Import and Use service.go

Handle API requests using service.go

Handle VP

Use the following to extract VC from VP in form of JSON text.

Since the form of VC varies according to the server's request, only JSON is supported here. The server can parse the VC into the per-defined form.

Last updated