IRMA server library
irmaserver is a Go library providing a HTTP server that handles IRMA session with the Yivi app, and functions for starting and managing IRMA sessions.
Installing
go get github.com/privacybydesign/irmago
Configuring
The server is configured by passing a server.Configuration instance to irmaserver.New(). For the options and their meaning, see Godoc.
Example
package main
import (
"github.com/privacybydesign/irmago/server"
"github.com/privacybydesign/irmago/server/irmaserver"
"net/http"
"fmt"
"encoding/json"
)
func main() {
configuration := &server.Configuration{
// Replace with address that Yivi apps can reach
URL: "http://localhost:1234/irma",
}
err := irmaserver.Initialize(configuration)
if err != nil {
// ...
}
http.Handle("/irma/", irmaserver.HandlerFunc())
http.HandleFunc("/createrequest", createFullnameRequest)
// Start the server
fmt.Println("Going to listen on :1234")
err = http.ListenAndServe(":1234", nil)
if err != nil {
fmt.Println("Failed to listen on :1234")
}
}
func createFullnameRequest(w http.ResponseWriter, r *http.Request) {
request := `{
"type": "disclosing",
"content": [{ "label": "Full name", "attributes": [ "pbdf.nijmegen.personalData.fullname" ]}]
}`
sessionPointer, token, err := irmaserver.StartSession(request, func (r *server.SessionResult) {
fmt.Println("Session done, result: ", server.ToJson(r))
})
if err != nil {
// ...
}
fmt.Println("Created session with token ", token)
// Send session pointer to frontend, which can render it as a QR
w.Header().Add("Content-Type", "text/json")
jsonSessionPointer, _ := json.Marshal(sessionPointer)
w.Write(jsonSessionPointer)
}
See also
- The Go library
requestorserverwraps the functions that this library exposes for starting and managing IRMA sessions into HTTP endpoints. - The
yivi irma servercommand wrapsrequestorserverinto an executable. - The client corresponding to this server is implemented by the IRMA mobile app.