Skip to content
Rails OAuth example without any gem, talk directly to GitHub API - [Server]
Ruby HTML
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
app
bin
config
db
lib/tasks
log
public
storage
tmp
vendor
.env.sample
.gitignore
.ruby-version
Gemfile
Gemfile.lock
README.md
Rakefile
config.ru

README.md

README

Following this great tutorial I could acomplish this workaround to access the GitHub API without any related Gem.

Basically there's a service dedicated to authenticate user. It redirects to the autorization page on Github, once the user autorizes the Rails app to access his GitHub profile it get the autorization code and uses it to get an access token and finally we can claim users information from GitHub using that token.

Then, we persist the user in the database using the gotten data from GitHub and right away we create a JWT to be returned to the client application which in this case is a ReactJS one.

Finally we redirect the user to the app client app URL ENV['FLASHCARDS_CLIENT_URL'].

We need to find a way to pass down the token when redirecting to the client URL so we can keep the user logged in and use the toke for further request.

  • This is the endpoint to access the authentication service.
    get '/auth/github', to: 'authentication#github', format: false
You can’t perform that action at this time.