Skip to content

Commit

Permalink
Merge 70c6594 into f5299a1
Browse files Browse the repository at this point in the history
  • Loading branch information
arekkas committed Oct 19, 2016
2 parents f5299a1 + 70c6594 commit 8671ccf
Show file tree
Hide file tree
Showing 91 changed files with 2,422 additions and 2,269 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ env:
language: go

go:
- 1.5
- 1.6
- 1.7

install:
Expand All @@ -31,7 +29,8 @@ script:
- $GOPATH/bin/hydra token client --skip-tls-verify

after_success:
- if [ "${TRAVIS_TAG}" != "" ] && [ "${TRAVIS_GO_VERSION}" == "1.7" ]; then gox -ldflags "-X github.com/ory-am/hydra/cmd.Version=`git describe --tags` -X github.com/ory-am/hydra/cmd.BuildTime=`TZ=UTC date -u '+%Y-%m-%dT%H:%M:%SZ'` -X github.com/ory-am/hydra/cmd.GitHash=`git rev-parse HEAD`" -output "dist/{{.Dir}}-{{.OS}}-{{.Arch}}"; fi
- |-
[ "${TRAVIS_TAG}" != "" ] && [ "${TRAVIS_GO_VERSION}" == "1.7" ] && gox -ldflags "-X github.com/ory-am/hydra/cmd.Version=`git describe --tags` -X github.com/ory-am/hydra/cmd.BuildTime=`TZ=UTC date -u '+%Y-%m-%dT%H:%M:%SZ'` -X github.com/ory-am/hydra/cmd.GitHash=`git rev-parse HEAD`" -output "dist/ {.Dir}}-{{.OS}}-{{.Arch}}"
deploy:
provider: releases
Expand Down
16 changes: 16 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Contribution Guide

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents**

- [Introduction](#introduction)
- [Contributing Code](#contributing-code)
- [Code Style](#code-style)
- [Developer’s Certificate of Origin](#developer%E2%80%99s-certificate-of-origin)
- [Pull request procedure](#pull-request-procedure)
- [Communication](#communication)
- [Conduct](#conduct)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## Introduction

We welcome and encourage community contributions to Hydra.

Since the project is still unstable, there are specific priorities for development. Pull requests that do not address these priorities will not be accepted until Hydra is production ready.
Expand Down
99 changes: 20 additions & 79 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,21 @@
[![HTTP API Documentation](https://img.shields.io/badge/docs-http%20api-blue.svg)](http://docs.hdyra.apiary.io/)
[![Code Documentation](https://img.shields.io/badge/docs-godoc-blue.svg)](https://godoc.org/github.com/ory-am/hydra)

Hydra is being developed by german-based company [Ory](https://ory.am).
Hydra is a runnable server implementation of the OAuth2 2.0 authorization framework and the OpenID Connect Core 1.0.

Hydra is being developed by german-based company [ORY](https://ory.am).
Join our [newsletter](http://eepurl.com/bKT3N9) to stay on top of new developments.
We offer basic support requests on [Google Groups](https://groups.google.com/forum/#!forum/ory-hydra/new) and [Gitter](https://gitter.im/ory-am/hydra)
as well as [consulting](mailto:hi@ory.am) around integrating Hydra into
your particular environment and [premium support](mailto:hi@ory.am).
We answer basic support requests on [Google Groups](https://groups.google.com/forum/#!forum/ory-hydra/new) and [Gitter](https://gitter.im/ory-am/hydra)
and offer [premium services](http://www.ory.am/products/hydra) around Hydra.

Hydra uses the security first OAuth2 and OpenID Connect SDK [Fosite](https://github.com/ory-am/fosite) and [Ladon](https://github.com/ory-am/ladon) for policy-based access control.
Hydra uses the security first OAuth2 and OpenID Connect SDK [Fosite](https://github.com/ory-am/fosite) and
the access control SDK [Ladon](https://github.com/ory-am/ladon).

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents**

- [What is Hydra?](#what-is-hydra)
- [What is Hydra / OAuth2 not?](#what-is-hydra--oauth2-not)
- [When does Hydra / OAuth2 make sense?](#when-does-hydra--oauth2-make-sense)
- [Feature Overview](#feature-overview)
- [Quickstart](#quickstart)
- [Installation](#installation)
- [Download binaries](#download-binaries)
Expand All @@ -52,76 +51,18 @@ Hydra uses the security first OAuth2 and OpenID Connect SDK [Fosite](https://git

## What is Hydra?

At first, there was the monolith. The monolith worked well with the bespoke authentication module.
Then, the web evolved into an elastic cloud that serves thousands of different user agents
in every part of the world.

Hydra is driven by the need for a **scalable, low-latency, in memory
Access Control, OAuth2, and OpenID Connect layer** that integrates with every identity provider you can imagine.

* Hydra is built security first: architecture and work flows are designed to neutralize various common (OWASP TOP TEN) and uncommon attack vectors. [Learn more](https://ory-am.gitbooks.io/hydra/content/basics/security.html).
* Hydra can manage all of your access control needs, such as policy based access control and access token validation. [Learn more](https://ory-am.gitbooks.io/hydra/content/access-control.html).
* Hydra depends on an identity provider of your choosing, e.g. [authboss](https://github.com/go-authboss/authboss), and works with any identity provider that is able to read and issue JSON Web Tokens. [Learn more](https://ory-am.gitbooks.io/hydra/content/oauth2/consent.html).
* Hydra has nano-second latency on high profile endpoints, overwhelmingly efficient memory and CPU consumption and scales effortlessly. [Learn more](https://ory-am.gitbooks.io/hydra/content/basics/architecture.html).
* Hydra focuses on ease of use, integration, management and operation. [Get Hydra up and running in 5 Minutes](https://ory-am.gitbooks.io/hydra/content/demo.html).
* Hydra helps you manage [Social Login Connections](https://ory-am.gitbooks.io/hydra/content/sso.html) as well as [JSON Web Keys](https://ory-am.gitbooks.io/hydra/content/jwk.html) and is planned to help you manage User Groups and Two Factor Authentication as well.
* Hydra is available through [Docker](https://hub.docker.com/r/oryam/hydra/) and relies on RethinkDB for persistence.
Database drivers are extensible in case you want to use RabbitMQ, MySQL, MongoDB, or some other database instead.

Hydra is built for high volume environments and is capable of serving tens of thousands of simultaneous requests per second per instance. Read [this issue](https://github.com/ory-am/hydra/issues/161) for information on reproducing these benchmarks yourself.

### What is Hydra / OAuth2 not?

I am new to all of this. When should I reconsider if using OAuth2 / Hydra is the right choice for me?

1. Hydra is not something that manages user accounts. Hydra does not offer user registration, password reset, user
login, sending confirmation emails. This is what the *Identity Provider* ("login endpoint") is responsible for.
The communication between Hydra and the Identity Provider is called [*Consent Flow*](https://ory-am.gitbooks.io/hydra/content/oauth2/consent.html).
[Auth0.com](https://auth0.com) is an Identity Provider. We might implement this feature at some point and if, it is going to be a different product.
2. If you think running an OAuth2 Provider can solve your user authentication ("log a user in"), Hydra is probably not for you. OAuth2 is a delegation protocol:

> The OAuth 2.0 authorization framework enables a third-party application *[think: a dropbox app that manages your dropbox photos]*
to obtain limited access to an HTTP service, either on behalf of *[do you allow "amazing photo app" to access all your photos?]*
a resource owner *[user]* by orchestrating an approval interaction *[consent flow]* between the resource owner and the
HTTP service, or by allowing the third-party application *[OAuth2 Client App]* to obtain access on its own behalf.
- **[IETF](https://tools.ietf.org/html/rfc6749)**
3. If you are building a simple service for 50-100 registered users, OAuth2 and Hydra will be overkill.
4. Hydra does not support the OAuth2 resource owner password credentials flow.
5. Hydra has no user interface. You must manage OAuth2 Clients and other things using the RESTful endpoints.
A user interface is scheduled to accompany the stable release.

### When does Hydra / OAuth2 make sense?

1. If you want third-party developers to access your APIs, Hydra is the perfect fit. This is what an OAuth2 Provider does.
2. If you want to become a Identity Provider, like Google, Facebook or Microsoft, OpenID Connect and thus Hydra is a perfect fit.
3. Running an OAuth2 Provider works great with browser, mobile and wearable apps, as you can avoid storing user
credentials on the device, phone or wearable and revoke access tokens, and thus access privileges, at any time. Adding
OAuth2 complexity to your environment when you never plan to do (1),
might not be worth it. Our advice: write a pros/cons list.
4. If you have a lot of services and want to limit automated access (think: cronjobs) for those services,
OAuth2 might make sense for you. Example: The comment service is not allowed to read user passwords when fetching
the latest user profile updates.

## Feature Overview

1. **Availability:** Hydra uses pub/sub to have the latest data available in memory. The in-memory architecture allows for heavy duty workloads.
2. **Scalability:** Hydra scales effortlessly on every platform you can imagine, including Heroku, Cloud Foundry, Docker,
Google Container Engine and many more.
3. **Integration:** Hydra wraps your existing stack like a blanket and keeps it safe. Hydra uses cryptographic tokens to authenticate users and request their consent, no APIs required.
The deprecated php-3.0 authentication service your intern wrote? It works with that too, don't worry.
We wrote an example with React to show you what this could look like: [React.js Identity Provider Example App](https://github.com/ory-am/hydra-idp-react).
4. **Security:** Hydra leverages the security first OAuth2 framework **[Fosite](https://github.com/ory-am/fosite)**,
encrypts important data at rest, and supports HTTP over TLS (https) out of the box.
5. **Ease of use:** Developers and operators are human. Therefore, Hydra is easy to install and manage. Hydra does not care if you use React, Angular, or Cocoa for your user interface.
To support you even further, there are APIs available for *cryptographic key management, social log on, policy based access control, policy management, and two factor authentication (tbd).*
Hydra is packaged using [Docker](https://hub.docker.com/r/oryam/hydra/).
6. **Open Source:** Hydra is licensed under Apache Version 2.0
7. **Professional:** Hydra implements peer reviewed open standards published by [The Internet Engineering Task Force (IETF®)](https://www.ietf.org/) and the [OpenID Foundation](https://openid.net/)
and under supervision of the [LMU Teaching and Research Unit Programming and Modelling Languages](http://www.en.pms.ifi.lmu.de). No funny business.
8. <img src="docs/images/monitoring.gif" width="45%" align="right"> **Real Time:** Operation is a lot easier with real time. There are no caches,
no invalidation strategies and no magic - just simple, cloud native pub-sub. Hydra leverages RethinkDB, so check out their real time database monitoring too!
Hydra is a server implementation of the OAuth 2.0 authorization framework and the OpenID Connect Core 1.0. Existing OAuth2
implementations usually ship as libraries or SDKs such as [node-oauth2-server](https://github.com/oauthjs/node-oauth2-server)
or [fosite](https://github.com/ory-am/fosite/issues), or as fully featured identity solutions with user
management and user interfaces, such as [Dex](https://github.com/coreos/dex).

<br clear="all">
Implementing and using OAuth2 without understanding the whole specification is challenging and prone to errors, even when
SDKs are being used. The primary goal of Hydra is to make OAuth 2.0 and OpenID Connect 1.0 better accessible.

Hydra implements the flows described in OAuth2 and OpenID Connect 1.0 without forcing you to use a "Hydra User Management"
or some template engine or a predefined front-end. Instead it relies on HTTP redirection and cryptographic methods
to verify user consent allowing you to use Hydra with any authentication endpoint, be it [authboss](https://github.com/go-authboss/authboss),
[auth0.com](https://auth0.com/) or your proprietary PHP authentication.

## Quickstart

Expand Down Expand Up @@ -185,7 +126,7 @@ hydra
### 5 minutes tutorial: Run your very own OAuth2 environment

The **[tutorial](https://ory-am.gitbooks.io/hydra/content/demo.html)** teaches you to set up Hydra,
a RethinkDB instance and an exemplary identity provider written in React using docker compose.
a Posgres instance and an exemplary identity provider written in React using docker compose.
It will take you about 5 minutes to get complete the **[tutorial](https://ory-am.gitbooks.io/hydra/content/demo.html)**.

<img src="docs/images/oauth2-flow.gif" alt="OAuth2 Flow">
Expand All @@ -200,7 +141,7 @@ OAuth2 and OAuth2 related specifications are over 200 written pages. Implementin
Even if you use a secure SDK (there are numerous SDKs not secure by design in the wild), messing up the implementation
is a real threat - no matter how good you or your team is. To err is human.

An in-depth list of security features is listed [in the security guide](https://ory-am.gitbooks.io/hydra/content/basics/security.html).
An in-depth list of security features is listed [in the security guide](https://ory-am.gitbooks.io/hydra/content/faq/security.html).

## Reception

Expand Down
5 changes: 5 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Client struct {
ClientURI string `json:"client_uri" gorethink:"client_uri"`
LogoURI string `json:"logo_uri" gorethink:"logo_uri"`
Contacts []string `json:"contacts" gorethink:"contacts"`
Public bool `json:"public" gorethink:"public"`
}

func (c *Client) GetID() string {
Expand Down Expand Up @@ -65,3 +66,7 @@ func (c *Client) GetResponseTypes() fosite.Arguments {
func (c *Client) GetOwner() string {
return c.Owner
}

func (c *Client) IsPublic() bool {
return c.Public
}
14 changes: 7 additions & 7 deletions client/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
"fmt"
"net/http"

"github.com/pkg/errors"
"github.com/julienschmidt/httprouter"
"github.com/ory-am/common/rand/sequence"
"github.com/ory-am/hydra/firewall"
"github.com/ory-am/hydra/herodot"
"github.com/ory-am/ladon"
"github.com/pkg/errors"
)

type Handler struct {
Expand Down Expand Up @@ -46,10 +46,10 @@ func (h *Handler) Create(w http.ResponseWriter, r *http.Request, _ httprouter.Pa
return
}

if _, err := h.W.TokenAllowed(ctx, h.W.TokenFromRequest(r), &ladon.Request{
if _, err := h.W.TokenAllowed(ctx, h.W.TokenFromRequest(r), &firewall.TokenAccessRequest{
Resource: ClientsResource,
Action: "create",
Context: ladon.Context{
Context: map[string]interface{}{
"owner": c.Owner,
},
}, Scope); err != nil {
Expand Down Expand Up @@ -93,7 +93,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request, ps httprouter.P
return
}

if _, err := h.W.TokenAllowed(ctx, h.W.TokenFromRequest(r), &ladon.Request{
if _, err := h.W.TokenAllowed(ctx, h.W.TokenFromRequest(r), &firewall.TokenAccessRequest{
Resource: ClientsResource,
Action: "update",
Context: ladon.Context{
Expand All @@ -120,7 +120,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request, ps httprouter.P
func (h *Handler) GetAll(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
var ctx = herodot.NewContext()

if _, err := h.W.TokenAllowed(ctx, h.W.TokenFromRequest(r), &ladon.Request{
if _, err := h.W.TokenAllowed(ctx, h.W.TokenFromRequest(r), &firewall.TokenAccessRequest{
Resource: ClientsResource,
Action: "get",
}, Scope); err != nil {
Expand Down Expand Up @@ -152,7 +152,7 @@ func (h *Handler) Get(w http.ResponseWriter, r *http.Request, ps httprouter.Para
return
}

if _, err := h.W.TokenAllowed(ctx, h.W.TokenFromRequest(r), &ladon.Request{
if _, err := h.W.TokenAllowed(ctx, h.W.TokenFromRequest(r), &firewall.TokenAccessRequest{
Resource: fmt.Sprintf(ClientResource, id),
Action: "get",
Context: ladon.Context{
Expand All @@ -171,7 +171,7 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request, ps httprouter.P
var ctx = herodot.NewContext()
var id = ps.ByName("id")

if _, err := h.W.TokenAllowed(ctx, h.W.TokenFromRequest(r), &ladon.Request{
if _, err := h.W.TokenAllowed(ctx, h.W.TokenFromRequest(r), &firewall.TokenAccessRequest{
Resource: fmt.Sprintf(ClientResource, id),
Action: "delete",
}, Scope); err != nil {
Expand Down
7 changes: 3 additions & 4 deletions client/manager_memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ package client
import (
"sync"

"github.com/pkg/errors"
"github.com/imdario/mergo"
"github.com/ory-am/fosite"
"github.com/ory-am/fosite/hash"
"github.com/ory-am/hydra/pkg"
"github.com/pborman/uuid"
"github.com/imdario/mergo"
"github.com/pkg/errors"
)

type MemoryManager struct {
Clients map[string]Client
Hasher hash.Hasher
Hasher fosite.Hasher
sync.RWMutex
}

Expand Down
7 changes: 3 additions & 4 deletions client/manager_rethinkdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ import (
"time"

"github.com/Sirupsen/logrus"
"github.com/pkg/errors"
"github.com/imdario/mergo"
"github.com/ory-am/fosite"
"github.com/ory-am/fosite/hash"
"github.com/ory-am/hydra/pkg"
"github.com/pborman/uuid"
"github.com/pkg/errors"
"golang.org/x/net/context"
r "gopkg.in/dancannon/gorethink.v2"
"github.com/imdario/mergo"
)

type RethinkManager struct {
Expand All @@ -21,7 +20,7 @@ type RethinkManager struct {
sync.RWMutex

Clients map[string]Client
Hasher hash.Hasher
Hasher fosite.Hasher
}

func (m *RethinkManager) GetConcreteClient(id string) (*Client, error) {
Expand Down
Loading

0 comments on commit 8671ccf

Please sign in to comment.