(project string)
| 155 | } |
| 156 | |
| 157 | func createUsers(project string) { |
| 158 | for _, user := range getUsers() { |
| 159 | // Step 1. Build the token |
| 160 | claim := createUserClaim(user, project) |
| 161 | token := jwt.NewWithClaims(jwt.SigningMethodNone, claim) |
| 162 | if token == nil { |
| 163 | slog.ErrorContext(context.TODO(), "missing token") |
| 164 | os.Exit(1) |
| 165 | } |
| 166 | signedString, err := token.SignedString(jwt.UnsafeAllowNoneSignatureType) |
| 167 | if err != nil { |
| 168 | slog.ErrorContext(context.TODO(), "unable to sign token", "error", err) |
| 169 | os.Exit(1) |
| 170 | } |
| 171 | |
| 172 | u := "http://localhost:9099/identitytoolkit.googleapis.com/v1/accounts:signInWithIdp?key=fake" |
| 173 | |
| 174 | var jsonData = fmt.Appendf(nil, `{ |
| 175 | "postBody": "providerId=github.com&id_token=%s", |
| 176 | "requestUri": "http://localhost", |
| 177 | "returnIdpCredential": true, |
| 178 | "returnSecureToken": true |
| 179 | }`, signedString) |
| 180 | |
| 181 | // Step 2. Send the request to create the account |
| 182 | req, err := http.NewRequestWithContext(context.TODO(), http.MethodPost, u, bytes.NewBuffer(jsonData)) |
| 183 | if err != nil { |
| 184 | slog.ErrorContext(context.TODO(), "unable to create request", "error", err) |
| 185 | os.Exit(1) |
| 186 | } |
| 187 | req.Header.Set("Content-Type", "application/json") |
| 188 | |
| 189 | resp, err := http.DefaultClient.Do(req) |
| 190 | if err != nil { |
| 191 | slog.ErrorContext(context.TODO(), "unable to send request", "error", err) |
| 192 | os.Exit(1) |
| 193 | } |
| 194 | defer resp.Body.Close() |
| 195 | if resp.StatusCode != http.StatusOK { |
| 196 | slog.ErrorContext(context.TODO(), "unexpected status code", "status code", resp.StatusCode) |
| 197 | os.Exit(1) |
| 198 | } |
| 199 | |
| 200 | slog.InfoContext(context.TODO(), "user created", "email", user.Email) |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | type User struct { |
| 205 | Name string |
no test coverage detected