GithubHelp home page GithubHelp logo

benbalter / add-to-org Goto Github PK

View Code? Open in Web Editor NEW
26.0 5.0 8.0 334 KB

A simple Oauth App to automatically add users to an organization

License: MIT License

Ruby 86.59% HTML 7.29% Shell 6.13%
github organization oauth oauth-application ruby private-repository

add-to-org's Introduction

Add to Org

A simple Oauth App to automatically add users to an organization

Gem Version Build Status

Usage

Once set up, simply swap out your app's domain for any GitHub URL. E.g., github.com/government/best-practices/issues/1 becomes government-community.githubapp.com/government/best-practices/1. The user will be authenticated, added to the organization, and redirected to the requested GitHub URL.

Setup

Pro-tip: for a quickstart on how to set up the app, see the add-to-org demo app.

Credentials

You'll need a few different credentials for things to work:

A bot account

You'll need a dedicated "bot" account to add users to the organization:

  1. Create a bot account (a standard GitHub account not used by a human) that has admin rights to your organization.
  2. Create a personal access token for that user, with admin:org scope.

An OAuth application

You'll also need to create an OAUth application to validate users:

  1. Create an OAauth application within your organization via https://github.com/organizations/[YOUR-ORGANIZATION-NAME]/settings/applications/new
  2. The homepage URL should be the URL to your production instance.
  3. You can leave the callback URL blank. The default is fine.

Developing locally and deploying

Pro-tip: for a quickstart on how to set up the app, see the add-to-org demo app

  1. Create an oauth app (see above)
  2. Create a personal access token for a user with admin rights to the organization (see above)
  3. Add `gem 'add-to-org' to your project's Gemfile
  4. Add the following to your project's config.ru file:
require 'add-to-org'
run AddToOrg::App

Configuration

The following environmental values should be set:

  • GITHUB_ORG_ID - The name of the org to add users to
  • GITHUB_TEAM_ID - The ID of the team to add users to. Get this from the team page's URL
  • GITHUB_CLIENT_ID - Your OAuth app's client ID
  • GITHUB_CLIENT_SECRET - Your Oauth app's client secret
  • GITHUB_TOKEN - A personal access token for a user with admin rights to the organization
  • CONTACT_EMAIL - Point of contact to point users to if something goes wrong

Customizing the validator

For Add to Org to work, you'll also need to define a custom validator. You can do this in your configu.ru, or in a separate file included into config.ru. Here's an example of a validator that confirms the user has a verified @github.com email address:

require 'add-to-org'

AddToOrg.set_validator do |github_user, verified_emails, client|
  verified_emails.any? { |email| email[:email] =~ /@github\.com\z/ }
end

run AddToOrg::App

If you prefer, you can also pass the validator as a proc (or lambda):

AddToOrg.validator = proc { |github_user, verified_emails, client|
  verified_emails.any? { |email| email[:email] =~ /@github\.com\z/ }
}

The validator will receive three arguments to help you validate the user meets your criteria:

  • github_user - the Warden user, which will contain information like username, company, and human-readable name
  • verified_emails - an array of the user's verified emails
  • client - An Octokit.rb client, preset with the user's OAuth token.

The validator should return true if you'd like the current user added to the organization, or false if you'd like the user's request to be denied.

Customizing Views

There are three views, success, forbidden, and error. They're pretty boring by default, so you may want to swap them out for something a bit my snazzy. If you had a views directory along side your config.ru, you can do so like this in your config.ru file:

require 'add-to-org'

AddToOrgs.views_dir = File.expand_path("./views", File.dirname(__FILE__))

run AddToOrg::App

These are just sinatra .erb views. Take a look at the default views for an example.

Customizing static assets

You can also do the same with AddToOrg.public_dir for serving static assets (AddToOrg comes bundled with Bootstrap by default).

require 'add-to-org'

AddToOrgs.public_dir = File.expand_path("./public", File.dirname(__FILE__))

run AddToOrg::App

add-to-org's People

Contributors

benbalter avatar elstudio avatar gbinal avatar jezdez avatar waldoj 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

Watchers

 avatar  avatar  avatar  avatar  avatar

add-to-org's Issues

Help required

I am having some problems to set up the add-to-org to my organization, in the an-oauth-application i dont know what to do in the number 2), "The homepage URL should be the URL to your production instance." wich production instance?

Can someone help me?

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.