Web services and IFTTT

Cybersecurity First Principles in this lesson

Introduction and goals

In this lesson, we will learn how to plug and play different web services together to make some simple inventions that can automate tasks and send alerts, alarms, and messages based on various triggers.

Goals

By the end of this tutorial, you will be able to:

Materials Required

Prerequisite lessons

Table of Contents

    - [Cybersecurity First Principles in this lesson](#cybersecurity-first-principles-in-this-lesson)
    - [Introduction and goals](#introduction-and-goals)
    - [Goals](#goals)
    - [Materials Required](#materials-required)
    - [Prerequisite lessons](#prerequisite-lessons)
    - [Table of Contents](#table-of-contents)
    - [Before We Start](#before-we-start)
    - [Using web services](#using-web-services)
    - [Create an IFTTT Account](#create-an-ifttt-account)
    - [Everything is an applet](#everything-is-an-applet)
    - [Web Service Wizardry - your first applet](#web-service-wizardry---your-first-applet)
    - [Email a tweet](#email-a-tweet)
    - [Maker service to a Tweet](#maker-service-to-a-tweet)
    - [Self Exploration](#self-exploration)
    - [Cybersecurity First Principle Reflections](#cybersecurity-first-principle-reflections)
- [Lead Author](#lead-author)
    - [Acknowledgements](#acknowledgements)
    - [License](#license) <!-- TOC END -->

Before We Start

In the computational thinking lesson, you learned how to think systematically about a problem, discover the needs of problem stakeholders, design a solution, and test it. You will put those skills to work here.

Using web services

Web services are, as the name implies, services that live on the web. You use these all the time - mostly without knowing it. The internet is built on top of them. Google, Dropbox, Youtube, Twitter, and Facebook are just a few juggernauts that provide and use many different web services. In this lesson, we are going to use a mashup service called IFTTT (which stands for If This, Then That ). IFTTT is a great platform that talks to all kinds of other web services. This is a great example of the modularity cybersecurity first principle, because IFTTT can swap out components for others easily.

Create an IFTTT Account

To start we need to create an account:

Everything is an applet

Once you sign in, you will see might see some recipes that have already been made for you by the IFTTT team. A recipe is a design pattern that combines input and output behavior to do something cool. IFTTT refers to recipes as applets.

In IFTTT, everything you might want to do involves making an applet. An applet in IFTTT is a very simple app that involves two services. The basic premise is that if something happens in an input service (we will call it service A), then an output service (aka service B) should do something using its capabilities in response. Applets allow you to mix and match services as inputs and outputs in a similar way to how GPIO pins allow for different components to work together on the same interface. This is an example of modularity. The applet concept also encapsulates the service resource. This is a nice example of resource encapsulation because you don’t need to know how the service works or why, just that it accepts certain inputs/outputs and performs a certain kind of task.

Web Service Wizardry - your first applet

Let’s create a new applet that sends an email whenever an IFTTT trigger receives an email. This applet only uses one service - an email service, but uses two different features of the service.

applet

email sent

Check your email!

email worked

It worked!

This is a simple, but powerful tool. It also shows off resource encapsulation and abstraction. In terms of resource encapsulation, each of the services connected to IFTTT have many functions. These functions are encapsulated in a service (e.g. email in this example). The functions are also abstract because IFTTT doesn’t need to know how they work, just that they achieve a certain purpose (e.g. send an email). This helps model or abstract the implementation away from the design.

Email a tweet

Let’s make an app that accepts an email and then sends a tweet. This requires a Twitter account. If you don’t have and don’t want to create a Twitter account, feel free to skip this, but it’s fun!

twitter

Now let’s try it out. Send an email to trigger@applet.ifttt.com Make sure to include the #nebraskagencyber in the subject line. Then for the message put whatever you want to appear in your tweet. For mine, I went with the following:

twitter

This posted to twitter for me:

twitter

Pretty neat!

Maker service to a Tweet

In IFTTT there is a special service called a webhook that allows makers (like you!) to trigger events programmatically and pass them data. Lets experiment create an applet that sends a tweet using a webhook.

webhook

webhook

Now, triggering our maker webhook requires us to know a little bit about how this service works. Since it is not fully specified, it allows us to develop our own behaviors. For our tweet applet, we need to send the tweet event to maker service.

To figure out how we do that, visit this page: https://ifttt.com/maker_webhooks/settings

Here you will see the name of your account and the url that you can use to learn more about how the maker (webhook) service works.

webhook

Note the area outlined in red. This is something called your secret key. It is a unique secret just for you. Don’t share it! A secret key is kind of a like a password that programs uses to interface with other programs (like the service-to-service interactions we’ve been making with IFTTT).

If you want to visit the link shown there, you will get some detailed information about how this service works. This kind of information is called Service Documentation and can be used to execute the service.

In our tweet applet, we need to trigger an event called tweet. The service documentation tells us that the correct way to do so is to send a url request to the endpoint below:

https://maker.ifttt.com/trigger/tweet/with/key/your_key_goes_here

The documentation also tells us we can send parameters labeled Value1 to Value3. For our applet, we won’t need these right now, but keep this in mind - because later lessons will use these.

For now, visit the link above in a browser after you’ve inserted your own secret key into the url.

You have just connected one component (a browser) to a programmatic interface service and finally onward to twitter. Let’s check the result. You should see this in your browser:

webhook

And this on twitter:

webhook

Well done!

Self Exploration

Try some different designs yourself. You can combine any services with any other services. You could also change out some of the ingredients in the patterns we used to try some other ones.

Cybersecurity First Principle Reflections

In this lesson, we saw web services, such as IFTTT, can abstract away details about devices and instead focus on recipes or design patterns to describe how things work. We also saw that by keeping functionality modular, IFTTT can combine many services together. We only need to know about input and output parameters to link them together.

Web services use resource encapsulation to ensure that all functions related to the execution of an app or service are neatly within the scope of the service itself. IFTTT relies on services to be encapsulated so that they can provide external services a simple interface to use their abilities.

Data hiding is also important to prevent internal data in the service from being released outside of the service invocation. Local data remains hidden, while interfaces expose only what the service wants to release (for instance to IFTTT). This also relates to minimization because services can turn ports and other access off except for the specific interfaces it wants to leave open for other services to use.

Lead Author

Acknowledgements

Special thanks to Dr. Robin Gandhi for reviewing and editing this lesson.

License

Nebraska GenCyber Creative Commons License
is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Overall content: Copyright (C) 2017-2021 Dr. Matthew L. Hale, Dr. Robin Gandhi, and Dr. Briana B. Morrison.

Lesson content: Copyright (C) Dr. Matthew L. Hale 2021.
Creative Commons License
This lesson is licensed by the author under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.