Skip to content

Sm go #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
5e3cc48
Beginning move to go
motdotla May 31, 2014
3f79be0
AppCreate
motdotla Jun 4, 2014
b03373b
login/request, but not sending the email yet
motdotla Jun 4, 2014
8eea36e
deliver authcode email beginnings
motdotla Jun 4, 2014
825dd6f
Stringified templates to pass the short code to
motdotla Jun 4, 2014
1f59c72
Add text sending and move REDIS_URL to a variable
motdotla Jun 4, 2014
551ef2f
moves email delivery to a sub library
motdotla Jun 4, 2014
ba54244
Login confirm working - needs hash next
motdotla Jun 5, 2014
3f7d26f
Returns a hash in response
motdotla Jun 5, 2014
c1bdf5d
Update README to proper json
motdotla Jun 5, 2014
54d88a2
Update definitions and example requests
motdotla Jun 5, 2014
700d0ea
Remove click-to-cloud
motdotla Jun 6, 2014
909757b
Update example errors
motdotla Jun 6, 2014
7da74ae
Add logo
motdotla Jun 6, 2014
9046529
Update to show image
motdotla Jun 6, 2014
2769f16
REAMDE update
motdotla Jun 6, 2014
1bed54f
Update Procfile and go settings for heroku
motdotla Jun 6, 2014
71d7a44
Don't worry about catching error
motdotla Jun 6, 2014
104ec58
Some logging to debug on prod
motdotla Jun 6, 2014
203ee07
Update README to set FROM
motdotla Jun 6, 2014
a12e7aa
logger is part of classic
motdotla Jun 7, 2014
def37c0
Remove schema from README. moved to handshakejslogic
motdotla Jun 7, 2014
22f1231
Remove the logs there
motdotla Jun 7, 2014
19cf0f9
Remove log
motdotla Jun 7, 2014
ad1df49
Update option setting
motdotla Jun 8, 2014
d03bc81
Now passes the DB_ENCRYPTION_SALT. extra security
motdotla Jun 10, 2014
d25a380
Add a backup mailer - in case the first smtp service is down
motdotla Jun 10, 2014
09227b7
Add cross domain ability
motdotla Jun 16, 2014
f2e5387
Updates to get url parameters or form parameters
motdotla Jun 17, 2014
4f9c5cd
Now it can send as json, url params, or form encoded params
motdotla Jun 17, 2014
6710381
removed
motdotla Jun 17, 2014
a418c82
Add godeps
motdotla Jun 22, 2014
6671263
Update godeps to latest handshakejslogic
motdotla Jun 22, 2014
17e6a80
Remove godeps
motdotla Jun 22, 2014
b1b5443
Bring back them godeps
motdotla Jun 22, 2014
0456975
Update martini
motdotla Jun 22, 2014
37fd04a
Remove godeps
motdotla Jun 22, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
DB_ENCRYPTION_SALT="somesecretsaltthatis32characters"
REDIS_URL="redis://127.0.0.1:6379"
FROM="[email protected]"
SMTP_ADDRESS=smtp.sendgrid.net
SMTP_PORT=587
SMTP_USERNAME=username
SMTP_PASSWORD=password
BACKUP_SMTP_ADDRESS=smtp.mandrillapp.com
BACKUP_SMTP_PORT=587
BACKUP_SMTP_USERNAME=username
BACKUP_SMTP_PASSWORD=password
SUBJECT_TEMPLATE="Your code: {{authcode}}. Please enter it to login."
TEXT_TEMPLATE="Your code: {{authcode}}. Please enter it to login."
HTML_TEMPLATE="Your code: <b>{{authcode}}</b>. Please enter it to login."
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ tmp/
tmp/pids/*
log/
.env*
!.env.example
.ruby-version
node_modules
1 change: 1 addition & 0 deletions .godir
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
handshakejs-api
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
web: node app.js
web: handshakejs-api
160 changes: 85 additions & 75 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# [handshakejs](https://handshakejs.herokuapp.com) API Documentation

![](https://rawgithub.com/handshakejs/handshakejs-script/master/handshakejs.svg)
![](https://raw.githubusercontent.com/handshakejs/handshakejs-api/sm-go/handshakejs-logo.png)

**API platform for authenticating users without requiring a password.**

Expand All @@ -9,31 +9,50 @@
### Heroku

```bash
git clone https://github.com/sendgrid/handshakejs-api.git
git clone https://github.com/scottmotte/handshakejs-api.git
cd handshakejs-api
heroku create handshakejs
heroku create handshakejs-api -b https://github.com/kr/heroku-buildpack-go.git
heroku addons:add sendgrid
heroku addons:add redistogo
git push heroku master
heroku config:set [email protected]
heroku config
```

Next, create your first app.
Note the REDISTOGOURL, SENGRID_PASSWORD, and SENDGRID_USERNAME.

```
heroku config:set DB_ENCRYPTION_SALT="somesecretsaltthatis32characters"
heroku config:set REDIS_URL=REDISTOGOURL
heroku config:set [email protected]
heroku config:set SMTP_ADDRESS=smtp.sendgrid.net
heroku config:set SMTP_PORT=587
heroku config:set SMTP_USERNAME=SENDGRID_USERNAME
heroku config:set SMTP_PASSWORD=SENDGRID_PASSWORD
heroku config:set SUBJECT_TEMPLATE="Your code: {{authcode}}. Please enter it to login."
heroku config:set TEXT_TEMPLATE="Your code: {{authcode}}. Please enter it to login."
heroku config:set HTML_TEMPLATE="Your code: <b>{{authcode}}</b>. Please enter it to login."
heroku config
```

Finally, deploy it.

```bash
curl -X POST https://handshakejs.herokuapp.com/api/v0/apps/create.json \
-d "[email protected]" \
-d "app_name=your_app_name"
```
git push heroku master
```

Next, create your first app. Replace email and app_name with your information.

<https://handshakejs-api.herokuapp.com/api/v1/apps/create.json?email=[email]&app_name=[app_name]>

Nice, that's all it takes to get your authentication system running. Now let's plug that into our app using the embeddable JavaScript.

### Old, this will move to a separate spot probably with instructions.

Place a script tag wherever you want the login form displayed.

```html
<script src='/path/to/handshake.js'
data-app_name="your_app_name"
data-root_url="https://handshakejs.herokuapp.com"></script>
data-root_url="https://handshakejs-api.herokuapp.com"></script>
```

Get the latest [handshake.js here](https://github.com/sendgrid/handshakejs-script/blob/master/build/handshake.js). Replace the `data-app_name` with your own.
Expand Down Expand Up @@ -63,21 +82,6 @@ Then you'd setup a route in your app at /login/success to do something like this
end
```

### Click to cloud (beta)

You can optionally install using `click-to-cloud`. Click to cloud is a binary I'm building to make it easier to deploy
small application to cloud Paas like Heroku. I personally, use this approach, but your mileage may vary.

First, [install click-to-cloud](https://github.com/scottmotte/click-to-cloud#installation) on your machine.

Second, run the following command.

```bash
click-to-cloud --repo https://github.com/sendgrid/handshakejs-api.git
```

That's it. That will install your application to Heroku.

## API Overview

The [handshakejs.herokuapp.com](https://handshakejs.herokuapp.com) API is based around REST. It uses standard HTTP authentication. [JSON](https://www.json.org/) is returned in all responses from the API, including errors.
Expand All @@ -92,7 +96,7 @@ I've tried to make it as easy to use as possible, but if you have any feedback p

### API Endpoint

* https://handshakejs.herokuapp.com/api/v0
* https://handshakejs-api.herokuapp.com/api/v1

## Apps

Expand All @@ -105,35 +109,41 @@ Pass an email and app_name to create your app at handshakejs.herokuapp.com.
#### Definition

```bash
POST https://handshakejs.herokuapp.com/api/v0/apps/create.json
ANY https://handshakejs-api.herokuapp.com/api/v1/apps/create.json?app_name=[app_name]&email=[email]&salt=[salt]
```

#### Required Parameters

* email
* app_name

#### Optional Parameters

* email
* salt

#### Example Request

```bash
curl -X POST https://handshakejs.herokuapp.com/api/v0/apps/create.json \
-d "[email protected]" \
-d "app_name=myapp"
```
<https://handshakejs-api.herokuapp.com/api/v1/apps/create.json?app_name=[app_name]&email=[email]&salt=[salt]>

#### Example Response
```javascript
{
success: true,
app: {
email: "[email protected]",
app_name: "myapp",
salt: "the_default_generated_salt_that_you_should_keep_secret"
}
"apps": [{
"email": "[email protected]",
"app_name": "myapp",
"salt": "the_default_generated_salt_that_you_should_keep_secret"
}]
}
```

#### Example Error
```javascript
{
errors: [{
"code": "not_unique",
"field": "app_name",
"message": "app_name must be unique"
}]
}
```

Expand All @@ -146,7 +156,7 @@ Request a login.
#### Definition

```bash
POST https://handshakejs.herokuapp.com/api/v0/login/request.json
ANY https://handshakejs-api.herokuapp.com/api/v0/login/request.json?email=[email]&app_name=[app_name]
```

#### Required Parameters
Expand All @@ -156,21 +166,27 @@ POST https://handshakejs.herokuapp.com/api/v0/login/request.json

#### Example Request

```bash
curl -X POST https://handshakejs.herokuapp.com/api/v0/login/request.json \
-d "[email protected]" \
-d "app_name=your_app_name"
```
<https://handshakejs-api.herokuapp.com/api/v0/login/request.json?email=[email]&app_name=[app_name]>

#### Example Response
```javascript
{
success: true,
identity: {
email: "[email protected]",
app_name: "your_app_name",
authcode_expired_at: "1382833591309"
}
"identities": [{
"email": "[email protected]",
"app_name": "your_app_name",
"authcode_expired_at": "1382833591309"
}]
}
```

#### Example Error
```javascript
{
"errors": [{
"code": "required",
"field": "email",
"message": "email cannot be blank"
}]
}
```

Expand All @@ -181,7 +197,7 @@ Confirm a login. Email and authcode must match to get a success response back.
#### Definition

```bash
POST https://handshakejs.herokuapp.com/api/v0/login/confirm.json
ANY https://handshakejs-api.herokuapp.com/api/v1/login/confirm.json?email=[email]&authcode=[authcode]&app_name=[app_name]
```

#### Required Parameters
Expand All @@ -192,32 +208,26 @@ POST https://handshakejs.herokuapp.com/api/v0/login/confirm.json

#### Example Request

```bash
curl -X POST https://handshakejs.herokuapp.com/api/v0/login/confirm.json \
-d "[email protected]" \
-d "authcode=7389" \
-d "app_name=your_app_name"
```
<https://handshakejs-api.herokuapp.com/api/v1/login/confirm.json?email=[email]&authcode=[authcode]&app_name=[app_name]>

#### Example Response
```javascript
{
success: true,
identity: {
email: "[email protected]",
app_name: "your_app_name",
authcode: "7389"
}
"identities": [{
"email": "[email protected]",
"app_name": "your_app_name",
"hash": "523f325279fd3446a78894b55cf4d777"
}]
}
```

## Database Schema with Redis

apps - collection of keys with all the app_names in there. SADD

apps/myappname - hash with all the data in there. HSET or HMSET

apps/theappname/identities - collection of keys with all the identities' emails in there. SADD

apps/theappname/identities/emailaddress HSET or HMSET

#### Example Error
```javascript
{
"errors": [{
"code": "incorrect",
"field": "authcode",
"message": "the authcode was incorrect"
}]
}
```
Loading