I want to build a rails api for fb login using, ionic framework. Till now I've successfully created a web base application and it's successfully authenticating with Facebook.
Now I want to do the same but with ionic based app.
Questions?
- Is this possible to write a rails api using omniauth and using the fb authentication api with ionic.
- If it's(1) is possible than what kind of json request is to be made or returned.
Couldn't find anything over the web about it, nor any github project of rails with ionic (fb login).
My Current code:
Controller:
class SessionsController < ApplicationController
def create
user = User.from_omniauth(env["omniauth.auth"])
session[:user_id] = user.id
redirect_to root_url
end
def destroy
session[:user_id] = nil
redirect_to root_url
end
end
Model:
class User < ActiveRecord::Base
def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.uid).first_or_initialize do |user|
user.provider = auth.provider
user.uid = auth.uid
user.name = auth.info.name
user.oauth_token = auth.credentials.token
user.oauth_expires_at = Time.at(auth.credentials.expires_at)
user.save!
end
end
end
Initializers:
OmniAuth.config.logger = Rails.logger
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, "123", "abc"
end