Skip to content
Snippets Groups Projects

Modify ocm client

Merged Yordan Kinkov requested to merge 3-modify-ocm-client into main
All threads resolved!
Files
3
+ 32
8
package ocm
import (
"bytes"
"context"
"encoding/json"
"fmt"
@@ -30,14 +29,39 @@ func New(addr string, opts ...Option) *Client {
}
// GetLoginProofInvitation calls the "invitation" endpoint on
// the "out-of-band" protocol in the OCM service.
func (c *Client) GetLoginProofInvitation(ctx context.Context, r *LoginProofInvitationRequest) (*LoginProofInvitationResponse, error) {
b, err := json.Marshal(r)
// the "out-of-band" protocol in the OCM.
func (c *Client) GetLoginProofInvitation(ctx context.Context, query string) (*LoginProofInvitationResponse, error) {
req, err := http.NewRequestWithContext(ctx, "POST", c.addr+"/proof/v1/out-of-band-proof?"+query, nil)
if err != nil {
return nil, err
}
req, err := http.NewRequestWithContext(ctx, "POST", c.addr+"/out-of-band/1.0/invitation", bytes.NewReader(b))
resp, err := c.httpClient.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close() // nolint:errcheck
if resp.StatusCode != http.StatusCreated && resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected response code: %d", resp.StatusCode)
}
bytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
var response LoginProofInvitationResponse
if err := json.Unmarshal(bytes, &response); err != nil {
return nil, err
}
return &response, nil
}
// GetLoginProofResult calls the "find-by-presentation-id" endpoint in the OCM.
func (c *Client) GetLoginProofResult(ctx context.Context, presentationID string) (*LoginProofResultResponse, error) {
req, err := http.NewRequestWithContext(ctx, "GET", c.addr+"/proof/v1/find-by-presentation-id?presentationId="+presentationID, nil)
if err != nil {
return nil, err
}
@@ -48,7 +72,7 @@ func (c *Client) GetLoginProofInvitation(ctx context.Context, r *LoginProofInvit
}
defer resp.Body.Close() // nolint:errcheck
if resp.StatusCode != http.StatusCreated && resp.StatusCode != http.StatusOK {
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected response code: %d", resp.StatusCode)
}
@@ -57,10 +81,10 @@ func (c *Client) GetLoginProofInvitation(ctx context.Context, r *LoginProofInvit
return nil, err
}
var response *LoginProofInvitationResponse
var response LoginProofResultResponse
if err := json.Unmarshal(bytes, &response); err != nil {
return nil, err
}
return response, nil
return &response, nil
}
Loading