Jebemti mater
Jebemti mater

Reputation: 124

Send API-key inside HTML Form

So I have an API Key for my Webservice. Everytime a user registers I send him an email for him to verify his account. This looks like this:

public class EmailSender {

private static final String username = "[email protected]";
private static final String password = "uthoughiwillshowyoumypassword?";

public static void sendVerificationCode(String receiverusername, String receiveremail, String code) throws Exception {
    Properties prop = new Properties();
    prop.put("mail.smtp.host", "smtp.gmail.com");
    prop.put("mail.smtp.port", "587");
    prop.put("mail.smtp.auth", "true");
    prop.put("mail.smtp.starttls.enable", "true"); //TLS

    Session session = Session.getInstance(prop,
            new javax.mail.Authenticator() {
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(username, password);
        }
    });

    MimeMessage message = new MimeMessage(session);
    message.addRecipient(Message.RecipientType.TO, new InternetAddress(receiveremail));
    message.setSubject("Verification Code");

    MimeBodyPart messageBodyPart = new MimeBodyPart();
    messageBodyPart.setText("<form action=\"https://pathtomywebserviceurl.com/verify/"+code+"\">\n" +
    "<input type=\"submit\" value=\"Verify\" />\n" +
     "</form>", "UTF-8", "html");

    Multipart multipart = new MimeMultipart();
    multipart.addBodyPart(messageBodyPart);

    message.setContent(multipart);

    Transport.send(message);
}

When he clicks on the button the user actually makes a request to my webservice with his token as a parameter. But now I want also that my API-Key is send as eg. an http header so that I can extract the API-Key from the user verify request and check if the API-Key equals to the actually API-Key. Right now I only send the code but not the API-Key.

Upvotes: 1

Views: 1852

Answers (1)

Lebron11
Lebron11

Reputation: 666

Use a hidden form element:

<input type="hidden" id="myApiKey" name="myApiKey" value="myApiKeyValue">

Upvotes: 1

Related Questions