Skip to content
Snippets Groups Projects
Commit 0ab4ff22 authored by Yordan Kinkov's avatar Yordan Kinkov
Browse files

#3 modify ocm client

parent 30686f41
No related branches found
No related tags found
1 merge request!12Modify ocm client
Pipeline #52807 failed with stage
in 28 seconds
......@@ -6,6 +6,12 @@ import (
"fmt"
"io"
"net/http"
"net/url"
)
const (
proofOutOfBandPath = "/proof/v1/out-of-band-proof"
proofPresentationPath = "/proof/v1/find-by-presentation-id"
)
// Client is the OCM service client
......@@ -30,12 +36,18 @@ func New(addr string, opts ...Option) *Client {
// GetLoginProofInvitation calls the "invitation" endpoint on
// 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)
func (c *Client) GetLoginProofInvitation(ctx context.Context, credTypes []string) (*LoginProofInvitationResponse, error) {
req, err := http.NewRequestWithContext(ctx, "POST", c.addr+proofOutOfBandPath, nil)
if err != nil {
return nil, err
}
v := url.Values{}
for _, t := range credTypes {
v.Add("type", t)
}
req.URL.RawQuery = v.Encode()
resp, err := c.httpClient.Do(req)
if err != nil {
return nil, err
......@@ -43,7 +55,7 @@ func (c *Client) GetLoginProofInvitation(ctx context.Context, query string) (*Lo
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)
return nil, fmt.Errorf("unexpected response code: %s", resp.Status)
}
bytes, err := io.ReadAll(resp.Body)
......@@ -61,11 +73,15 @@ func (c *Client) GetLoginProofInvitation(ctx context.Context, query string) (*Lo
// 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)
req, err := http.NewRequestWithContext(ctx, "GET", c.addr+proofPresentationPath, nil)
if err != nil {
return nil, err
}
v := url.Values{}
v.Add("presentationId", presentationID)
req.URL.RawQuery = v.Encode()
resp, err := c.httpClient.Do(req)
if err != nil {
return nil, err
......@@ -73,7 +89,7 @@ func (c *Client) GetLoginProofResult(ctx context.Context, presentationID string)
defer resp.Body.Close() // nolint:errcheck
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected response code: %d", resp.StatusCode)
return nil, fmt.Errorf("unexpected response code: %s", resp.Status)
}
bytes, err := io.ReadAll(resp.Body)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment