Add API Authorization
This commit is contained in:
parent
66ebd5e622
commit
702b46f416
|
@ -0,0 +1,10 @@
|
||||||
|
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
||||||
|
def doorkeeper
|
||||||
|
oauth_data = request.env["omniauth.auth"]
|
||||||
|
@user = User.find_or_create_for_doorkeeper_oauth(oauth_data)
|
||||||
|
@user.update_doorkeeper_credentials(oauth_data)
|
||||||
|
@user.save
|
||||||
|
|
||||||
|
sign_in_and_redirect @user
|
||||||
|
end
|
||||||
|
end
|
|
@ -147,6 +147,13 @@ class Admin::SitesController < OrbitBackendController
|
||||||
render :text => "success"
|
render :text => "success"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def generate_site_token
|
||||||
|
begin
|
||||||
|
self.site_token = SecureRandom.uuid.gsub('-','')
|
||||||
|
self.save
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def update_design(design)
|
def update_design(design)
|
||||||
|
|
|
@ -479,4 +479,13 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def check_central_server_connection
|
||||||
|
site = Site.first
|
||||||
|
if site.site_token?
|
||||||
|
flash[:notice]="Connected to the Store"
|
||||||
|
else
|
||||||
|
flash[:notice]="To Access the Store Please Connect It"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -46,14 +46,15 @@ class Site
|
||||||
field :address
|
field :address
|
||||||
field :phone_number, :type => Array,:default=>[]
|
field :phone_number, :type => Array,:default=>[]
|
||||||
field :mobile_bar_color, :type => Array, :default=>[]
|
field :mobile_bar_color, :type => Array, :default=>[]
|
||||||
|
field :site_token
|
||||||
|
|
||||||
field :mobile_on, :type => Boolean, :default => false
|
field :mobile_on, :type => Boolean, :default => false
|
||||||
|
|
||||||
belongs_to :design
|
belongs_to :design
|
||||||
has_many :site_metas, :autosave => true, :dependent => :destroy
|
has_many :site_metas, :autosave => true, :dependent => :destroy
|
||||||
validate :in_use_locales, :minimum_enabled_locales
|
validate :in_use_locales, :minimum_enabled_locales
|
||||||
|
|
||||||
|
index({ access_token: 1}, { unique: true })
|
||||||
|
|
||||||
def minimum_enabled_locales
|
def minimum_enabled_locales
|
||||||
size = self.in_use_locales.length
|
size = self.in_use_locales.length
|
||||||
if size < 1
|
if size < 1
|
||||||
|
@ -96,4 +97,11 @@ class Site
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def generate_site_token
|
||||||
|
begin
|
||||||
|
self.site_token = SecureRandom.uuid.gsub('-','')
|
||||||
|
self.save
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
store_settings:
|
store_settings:
|
||||||
url: "http://store.tp.rulingcom.com"
|
url: "http://store.tp.rulingcom.com"
|
||||||
|
api_key: "cc6ae8d0aa0a730792cf519225c40099"
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
module OmniAuth
|
||||||
|
module Strategies
|
||||||
|
class Doorkeeper < OmniAuth::Strategies::OAuth2
|
||||||
|
option :name, :doorkeeper
|
||||||
|
|
||||||
|
option :client_options, {
|
||||||
|
:site => "http://localhost:8000",
|
||||||
|
:authorize_path => "/oauth/authorize"
|
||||||
|
}
|
||||||
|
|
||||||
|
uid do
|
||||||
|
raw_info["id"]
|
||||||
|
end
|
||||||
|
|
||||||
|
info do
|
||||||
|
{
|
||||||
|
:email => raw_info["email"]
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def raw_info
|
||||||
|
@raw_info ||= access_token.get('/api/v1/me.json').parsed
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,9 @@
|
||||||
|
class Store
|
||||||
|
include HTTParty
|
||||||
|
base_uri 'http://localhost:3000'
|
||||||
|
|
||||||
|
def post(text)
|
||||||
|
options = { :body => {:status => text}, :token => @auth }
|
||||||
|
self.class.post('/api/clients', options)
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue