Coder Social home page Coder Social logo

yusufsyaifudin / oauth2-example-hydra Goto Github PK

View Code? Open in Web Editor NEW
47.0 3.0 16.0 48 KB

Login and Consent ory/hydra example. Read article here https://yusufs.medium.com/practical-example-of-implementing-oauth-2-0-using-ory-hydra-fbaa2765d94f

Go 76.51% HTML 23.49%
oauth2-server oauth2-client ory-hydra authorization-code-grant authorization-server

oauth2-example-hydra's Introduction

Sample implementation of OAUTH2 using Hydra

This repository will explain you about:

  • How to create an Authentication Server and then use ory/hydra as Authorization server
  • How to implement "Sign With {put-your-app-name}" for single identity management for your app. This exactly the same as building "Sign Up using Google" or similar services for your own app.

How to run, step by step

Clone this repository. Then run go mod download.

Run ory/hydra server

This will run using Postgres as database and Jaeger as a tracing vendor.

$ docker-compose up

Create an OAUTH2 client

This will create an OAUTH2 client using hydra cli. Otherwise, you can also create using REST API.

$ docker-compose exec hydra hydra clients create \
--endpoint http://127.0.0.1:4445/ \
--name MyApp \
--id myclient \
--secret mysecret \
--grant-types authorization_code,refresh_token \
--response-types code,id_token \
--callbacks http://localhost:1234/callbacks \
--token-endpoint-auth-method client_secret_post \
--scope offline,users.write,users.read,users.edit,users.delete

or

curl -X POST 'http://localhost:4445/clients' \
-H 'Content-Type: application/json' \
--data-raw '{
    "client_id": "myclient",
    "client_name": "MyApp",
    "client_secret": "mysecret",
    "grant_types": ["authorization_code", "refresh_token"],
    "redirect_uris": ["http://localhost:1234/callbacks"],
    "response_types": ["code", "id_token"],
    "scope": "offline users.write users.read users.edit users.delete",
    "token_endpoint_auth_method": "client_secret_post"
}'

Please note scope is separated by space.

If you made wrong request params, you cannot create with the same client id, You must delete it first by doing this:

docker-compose exec hydra hydra clients delete --endpoint http://127.0.0.1:4445/ <client-id>

or

curl -X DELETE 'http://localhost:4445/clients/<client-id>'

Run Identity Provider (Resource Server)

$ go run cmd/authc/main.go

Run OAuth 2.0 Client App

$ REDIRECT_URL=http://localhost:1234/callbacks CLIENT_ID=myclient CLIENT_SECRET=mysecret go run cmd/frontend/main.go

Access the client App

Access http://localhost:1234 then try to authorize the application.

Include HTML in Binary

$ go get -u github.com/shuLhan/go-bindata/...
$ go-bindata -o views/view.go -ignore=view.go views/...

oauth2-example-hydra's People

Contributors

yusufsyaifudin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.