Memebrships: Refactor Store interface

Use unified memberships table.
Add few internal API endpoints.

Change-Id: I80ac5a0f5c262e04d7898cca571b938a35d68d39
diff --git a/core/auth/ui/api.go b/core/auth/ui/api.go
index b8c5bad..cced90d 100644
--- a/core/auth/ui/api.go
+++ b/core/auth/ui/api.go
@@ -129,6 +129,10 @@
 	}
 }
 
+type identityCreateResp struct {
+	Id string `json:"id"`
+}
+
 func (s *APIServer) identityCreate(w http.ResponseWriter, r *http.Request) {
 	var req identityCreateReq
 	if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
@@ -157,16 +161,26 @@
 		http.Error(w, "failed", http.StatusInternalServerError)
 		return
 	}
-	if resp.StatusCode != http.StatusCreated {
-		var e ErrorResponse
-		if err := json.NewDecoder(resp.Body).Decode(&e); err != nil {
+	if resp.StatusCode == http.StatusCreated {
+		var idResp identityCreateResp
+		if err := json.NewDecoder(resp.Body).Decode(&idResp); err != nil {
 			http.Error(w, "failed to decode", http.StatusInternalServerError)
 			return
 		}
-		errorMessages := extractKratosErrorMessage(e)
-		replyWithErrors(w, errorMessages)
+		if err := json.NewEncoder(w).Encode(idResp); err != nil {
+			http.Error(w, "failed to decode", http.StatusInternalServerError)
+			return
+		}
 		return
 	}
+	var e ErrorResponse
+	if err := json.NewDecoder(resp.Body).Decode(&e); err != nil {
+		http.Error(w, "failed to decode", http.StatusInternalServerError)
+		return
+	}
+	errorMessages := extractKratosErrorMessage(e)
+	replyWithErrors(w, errorMessages)
+	return
 }
 
 type changePasswordReq struct {