@@ -12,18 +12,18 @@ import (
1212 "code.miracl.com/maas/maas/src/lib/gomiracl/wrap"
1313)
1414
15- func createSession (httpClient * http.Client , userID string ) (* sessionResponse , error ) {
15+ func createSession (httpClient * http.Client , projectID , userID string ) (* sessionResponse , error ) {
1616 sessionRequest := & struct {
1717 ProjectID string `json:"projectId"`
1818 UserID string `json:"userId"`
1919 }{
20- options . projectID ,
20+ projectID ,
2121 userID ,
2222 }
2323
2424 sessionResp , err := makeRequest (
2525 httpClient ,
26- options .apiURL + "/rps/v2/session" ,
26+ options .projectDomain + "/rps/v2/session" ,
2727 http .MethodPost ,
2828 sessionRequest ,
2929 header {Key : "Content-Type" , Value : "application/json" })
@@ -40,9 +40,9 @@ func createSession(httpClient *http.Client, userID string) (*sessionResponse, er
4040 return createSessionResponse , nil
4141}
4242
43- func register (httpClient * http.Client , userID , deviceName string , pin int , accessID string ) (i identity , err error ) {
43+ func register (httpClient * http.Client , projectID , userID , deviceName string , pin int , accessID string ) (i identity , err error ) {
4444 // Call to /verification endpoint.
45- verifyURL , err := verificationRequest (httpClient , userID , deviceName , accessID )
45+ verifyURL , err := verificationRequest (httpClient , userID , deviceName , accessID , projectID )
4646 if err != nil {
4747 return identity {}, err
4848 }
@@ -65,6 +65,28 @@ func register(httpClient *http.Client, userID, deviceName string, pin int, acces
6565 return id , nil
6666}
6767
68+ func getProjectID (httpClient * http.Client ) (projectID string , err error ) {
69+ resp , err := makeRequest (
70+ httpClient ,
71+ options .projectDomain + "/.well-known/project-configuration" ,
72+ "GET" ,
73+ nil ,
74+ )
75+ if err != nil {
76+ return "" , err
77+ }
78+
79+ var projectResponse * struct {
80+ ID string `json:"id"`
81+ }
82+
83+ if err := json .Unmarshal (resp , & projectResponse ); err != nil {
84+ return "" , err
85+ }
86+
87+ return projectResponse .ID , nil
88+ }
89+
6890func newIdentity (httpClient * http.Client , userID , deviceName , accessID , activationToken string , pin int ) (i identity , err error ) {
6991 // Call to /rps/v2/user endpoint.
7092 regResponse , err := registerRequest (httpClient , userID , deviceName , accessID , activationToken )
@@ -103,7 +125,7 @@ func newIdentity(httpClient *http.Client, userID, deviceName, accessID, activati
103125 }, nil
104126}
105127
106- func verificationRequest (httpClient * http.Client , userID , deviceName , accessID string ) (string , error ) {
128+ func verificationRequest (httpClient * http.Client , userID , deviceName , accessID , projectID string ) (string , error ) {
107129 clientIDAndSecret := options .clientID + ":" + options .clientSecret
108130 authHeaderValue := "Basic " + b64 .StdEncoding .EncodeToString ([]byte (clientIDAndSecret ))
109131
@@ -115,7 +137,7 @@ func verificationRequest(httpClient *http.Client, userID, deviceName, accessID s
115137 Delivery string `json:"delivery"`
116138 Authorization string `json:"-"`
117139 }{
118- options . projectID ,
140+ projectID ,
119141 userID ,
120142 deviceName ,
121143 accessID ,
@@ -125,7 +147,7 @@ func verificationRequest(httpClient *http.Client, userID, deviceName, accessID s
125147
126148 resp , err := makeRequest (
127149 httpClient ,
128- options .apiURL + "/verification" ,
150+ options .projectDomain + "/verification" ,
129151 "POST" ,
130152 payload ,
131153 header {Key : "Authorization" , Value : authHeaderValue },
@@ -158,7 +180,7 @@ func registerRequest(httpClient *http.Client, userID, deviceName, accessID, acti
158180
159181 resp , err := makeRequest (
160182 httpClient ,
161- options .apiURL + "/rps/v2/user" ,
183+ options .projectDomain + "/rps/v2/user" ,
162184 "PUT" ,
163185 payload ,
164186 header {Key : "X-MIRACL-CID" , Value : "mcl" },
@@ -180,7 +202,7 @@ var errInvalidSignatureResponse = errors.New("invalid signature response")
180202func signatureRequest (httpClient * http.Client , mpinID , regOTT string ) (* signatureResponse , error ) {
181203 resp , err := makeRequest (
182204 httpClient ,
183- fmt .Sprintf (options .apiURL + "/rps/v2/signature/%v?regOTT=%v" , mpinID , regOTT ),
205+ fmt .Sprintf (options .projectDomain + "/rps/v2/signature/%v?regOTT=%v" , mpinID , regOTT ),
184206 "GET" ,
185207 nil ,
186208 )
@@ -239,7 +261,7 @@ func verificationConfirmation(httpClient *http.Client, userID, code string) (str
239261
240262 resp , err := makeRequest (
241263 httpClient ,
242- options .apiURL + "/verification/confirmation" ,
264+ options .projectDomain + "/verification/confirmation" ,
243265 "POST" ,
244266 payload ,
245267 )
0 commit comments