Skip to content
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

Sm go #3

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Login confirm working - needs hash next
motdotla committed Jun 5, 2014
commit ba54244a6154ca36b68e310364e13147b2ca9fef
42 changes: 23 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -21,9 +21,7 @@ heroku config:set FROM=login@yourapp.com
Next, create your first app.

```bash
curl -X POST https://handshakejs.herokuapp.com/api/v0/apps/create.json \
-d "email=you@email.com" \
-d "app_name=your_app_name"
https://handshakejs.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.
@@ -33,7 +31,7 @@ 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.
@@ -92,7 +90,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/v1
* https://handshakejs-api.herokuapp.com/api/v1

## Apps

@@ -105,7 +103,7 @@ Pass an email and app_name to create your app at handshakejs.herokuapp.com.
#### Definition

```bash
POST|GET https://handshakejs.herokuapp.com/api/v1/apps/create.json
POST|GET https://handshakejs-api.herokuapp.com/api/v1/apps/create.json
```

#### Required Parameters
@@ -120,7 +118,7 @@ POST|GET https://handshakejs.herokuapp.com/api/v1/apps/create.json
#### Example Request

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

#### Example Response
@@ -154,7 +152,7 @@ Request a login.
#### Definition

```bash
POST|GET https://handshakejs.herokuapp.com/api/v1/login/request.json
POST|GET https://handshakejs-api.herokuapp.com/api/v1/login/request.json
```

#### Required Parameters
@@ -165,7 +163,7 @@ POST|GET https://handshakejs.herokuapp.com/api/v1/login/request.json
#### Example Request

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

#### Example Response
@@ -197,7 +195,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
https://handshakejs-api.herokuapp.com/api/v1/login/confirm.json
```

#### Required Parameters
@@ -209,21 +207,27 @@ 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=test@example.com" \
-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: {
identities: [{
email: "test@example.com",
app_name: "your_app_name",
authcode: "7389"
}
app_name: "your_app_name"
}]
}
```

#### Example Error
```javascript
{
errors: [{
code: "not_found",
field: "app_name",
message: "app_name could not be found"
}]
}
```

40 changes: 36 additions & 4 deletions app.go
Original file line number Diff line number Diff line change
@@ -31,7 +31,8 @@ var (
func main() {
loadEnvs()

handshakejslogic.Setup(REDIS_URL)
logic_options := &handshakejslogic.Options{}
handshakejslogic.Setup(REDIS_URL, logic_options)
handshakejstransport.Setup(SMTP_ADDRESS, SMTP_PORT, SMTP_USERNAME, SMTP_PASSWORD)

m := martini.Classic()
@@ -40,6 +41,7 @@ func main() {

m.Any("/api/v1/apps/create.json", AppsCreate)
m.Any("/api/v1/login/request.json", IdentitiesCreate)
m.Any("/api/v1/login/confirm.json", IdentitiesConfirm)

m.Run()
}
@@ -61,7 +63,7 @@ func AppsPayload(app map[string]interface{}) map[string]interface{} {
return payload
}

func IdentitiesPayload(identity map[string]interface{}) map[string]interface{} {
func IdentitiesCreatePayload(identity map[string]interface{}) map[string]interface{} {
email := identity["email"].(string)
app_name := identity["app_name"].(string)
authcode_expired_at := identity["authcode_expired_at"].(string)
@@ -74,6 +76,18 @@ func IdentitiesPayload(identity map[string]interface{}) map[string]interface{} {
return payload
}

func IdentitiesConfirmPayload(identity map[string]interface{}) map[string]interface{} {
email := identity["email"].(string)
app_name := identity["app_name"].(string)

identities := []interface{}{}
output_identity := map[string]interface{}{"email": email, "app_name": app_name}
identities = append(identities, output_identity)
payload := map[string]interface{}{"identities": identities}

return payload
}

func AppsCreate(req *http.Request, r render.Render) {
email := req.URL.Query().Get("email")
app_name := req.URL.Query().Get("app_name")
@@ -102,9 +116,27 @@ func IdentitiesCreate(req *http.Request, r render.Render) {
statuscode := determineStatusCodeFromLogicError(logic_error)
r.JSON(statuscode, payload)
} else {
deliverAuthcodeEmail(result)
go deliverAuthcodeEmail(result)
log.Println(result)

payload := IdentitiesCreatePayload(result)
r.JSON(200, payload)
}
}

func IdentitiesConfirm(req *http.Request, r render.Render) {
email := req.URL.Query().Get("email")
app_name := req.URL.Query().Get("app_name")
authcode := req.URL.Query().Get("authcode")

payload := IdentitiesPayload(result)
identity := map[string]interface{}{"email": email, "app_name": app_name, "authcode": authcode}
result, logic_error := handshakejslogic.IdentitiesConfirm(identity)
if logic_error != nil {
payload := ErrorPayload(logic_error)
statuscode := determineStatusCodeFromLogicError(logic_error)
r.JSON(statuscode, payload)
} else {
payload := IdentitiesConfirmPayload(result)
r.JSON(200, payload)
}
}