Slevin
Slevin

Reputation: 4222

Rails: authentication system based on external API

i'm building a Rails application to extend features of an existing online Rails app. The existing Rails app provides an API for authentication.

My approach: user X have an account at the existing Rails app. With these login data the user X should authenticate on my Rails app. The existing app offers a gem to connect to the API after login.

Whats the best method to store the information about a successful login? Should i use sessions? Or does Rails offer better methods for this?

Upvotes: 1

Views: 1066

Answers (1)

Yanhao
Yanhao

Reputation: 5294

I don't think Rails offers a standard method for this.

You can store user_id in session after successful authentication, then check session[:user_id] in application_controller on each request to see if the user has logged in or not.

See #250 Authentication from Scratch on RailsCasts.

Upvotes: 1

Related Questions