Giter VIP home page Giter VIP logo

oauth2orize-examples's Introduction

oauth2orize: oauth2 provider example

This example shows a provider which grants tokens in exchange for codes for

  • The client application
  • A user of the client application

Install

git clone https://github.com/gerges-beshay/oauth2orize-examples.git
pushd oauth2orize-examples
npm install

Usage

Locally

node app.js

Visit http://localhost:3000/login to see the server running locally.

  1. Download either Vercel Desktop (preferred) or Vercel CLI.
  2. Create a .vercelignore file in the root of the package (where package.json is located) with the following contents:
node_modules
.eslintrc
LICENSE.md
README.md
  1. Create a vercel.json file in the root of the package with the following contents:
{
  "version": 2,
  "builds": [
    {
      "src": "app.js",
      "use": "@now/node-server"
    }
  ],
  "routes": [
    {
      "src": "/(.*)",
      "dest": "app.js"
    }
  ]
}
  1. Execute vercel in the terminal/console. (If the command is not recognized, you might have to restart your computer.)
  2. Once you see the “Success! Deployment ready” message in the terminal, follow the URL of the deployment provided by the Vercel CLI.

Provider / Consumer Walkthrough

Interacting with this provider directly doesn't showcase it's oauth2 functionality.

  1. Visiting / takes you to a blank page... not too interesting
  2. /login will ask you for credentials.
  • If you login before an oauth request you are taken directly to permission dialog when that request happens
  • Otherwise you will be redirected here and then to the permission dialog
  1. /account will allow you to see your user details

In order to demo what this is actually accomplishing you'll need to run a consumer.

See https://github.com/coolaj86/example-oauth2orize-consumer

API

Below is a mapping of the API in the context of a passport-strategy

  • /dialog/authorize is the authorizationURL.
  • /oauth/token is the tokenURL
  • /api/userinfo is a protected resource that requires user permission
  • /api/clientinfo is a protected resource that requires a token generated from the client's id and secret
  • Usage of scope is not demonstrated in this example.

The standalone usable resources are

  • GET / nothing
  • GET /login lets you login, presented by /dialog/authorize if you haven't logged in
  • POST /login processes the login
  • GET /logout lets you logout
  • GET /account lets your view your user info

And then some internal resources that are of no concern for standalone users or consumers

  • POST /dialog/authorize/decision, processes the allow / deny

oauth2orize-examples's People

Contributors

adamhathcock avatar ajuhos avatar championswimmer avatar cnahliu avatar dependabot[bot] avatar lukaslohoff avatar luminousxlb avatar markstos avatar marvinschopf avatar mohd7469 avatar poziworld avatar zce 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  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  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

oauth2orize-examples's Issues

A path other than root

I am using your example, but want to host it on a path other than /. Is there a property I can set (or other approach) to achieve this simply?

AuthorizationError: Missing required parameter: response_type

I have an error when accessing /dialog/authorize after logged in.

the error message shown below

AuthorizationError: Missing required parameter: response_type at /var/www/html/oauth2orize-examples/node_modules/oauth2orize/lib/middleware/authorization.js:120:46 at pass (/var/www/html/oauth2orize-examples/node_modules/oauth2orize/lib/server.js:295:26) at pass (/var/www/html/oauth2orize-examples/node_modules/oauth2orize/lib/server.js:313:9) at pass (/var/www/html/oauth2orize-examples/node_modules/oauth2orize/lib/server.js:313:9) at Server._parse (/var/www/html/oauth2orize-examples/node_modules/oauth2orize/lib/server.js:318:5) at authorization (/var/www/html/oauth2orize-examples/node_modules/oauth2orize/lib/middleware/authorization.js:118:12) at Layer.handle [as handle_request] (/var/www/html/oauth2orize-examples/node_modules/express/lib/router/layer.js:95:5) at next (/var/www/html/oauth2orize-examples/node_modules/express/lib/router/route.js:137:13) at /var/www/html/oauth2orize-examples/node_modules/connect-ensure-login/lib/ensureLoggedIn.js:50:5 at Layer.handle [as handle_request] (/var/www/html/oauth2orize-examples/node_modules/express/lib/router/layer.js:95:5)

Duplication of 'db.clients.findByClientId()' in example

Hi.

My question is:

Why do we need to check client twice? Isn't it enough to fetch client in passport strategy and then simply use client object which was passed down to oauth2orize clientCredentials exchange handler? Or this duplication is just for demo purposes?

Thank you!

Basic /oauth/token does not work

curl -X POST "http://localhost:3000/oauth/token" -d "grant_type=password&client_id=abc123&client_secret=ssh-secret&username=bob&password=secret"

Error: {"error":"server_error","error_description":"authCode is not defined"}

Authorization Code Replay Vulnerability

The code in the Grant Flow doesn't invalidate the Authorization Code after it's used to successfully issue an access token, so you can reuse the authorization code to issue another access token. It's recommended to have authorization codes expire after some short window and to mark them as used once you've issued a token. The OAuth site goes into more detail about Authorization Codes here.

I'd be happy to make a pull request to expire tokens and remove them after they've been used (or at least invalidate them. Or at a minimum I can make a PR to add some comments to note how it should be done if implemented in a live application.

user.has_token and client.isTrusted

In the oauth2.js, I can see user.has_token and client.isTrusted, but I cannot find those method in the user and client models. Where is these method specified?

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.