Commit 724ff421 by mingyuan

app key

parent 651036db
module Dingtalk
class AppsController < BaseController
before_action :set_app, only: [:login]
before_action :set_app_by_corp, only: [:info]
before_action :set_new_app, only: [:login]
before_action :set_normal_app, only: [:info]
def info
result = @app.xx(params[:code])
......@@ -17,12 +17,12 @@ module Dingtalk
end
private
def set_app
@app = App.find params[:id]
def set_new_app
@app = NewlApp.find_by(app_key: params[:app_key])
end
def set_app_by_corp
@app = NormalApp.find_by corp_id: params[:corp_id]
def set_normal_app
@app = NormalApp.find_by(app_key: params[:app_key])
end
end
......
......@@ -15,7 +15,7 @@ module Dingtalk
attribute :oauth2_state, :string
attribute :jsapi_ticket_expires_at, :datetime
has_many :dingtalk_users, foreign_key: :appid, primary_key: :corp_id
has_many :dingtalk_users, foreign_key: :appid, primary_key: :app_key
end
def api
......
......@@ -9,7 +9,7 @@ module Dingtalk
def oauth2_url(scope = 'openid corpid', state: SecureRandom.hex(16), **host_options)
h = {
client_id: app_key,
redirect_uri: Rails.application.routes.url_for(controller: 'dingtalk/apps', action: 'login', id: id, **host_options),
redirect_uri: Rails.application.routes.url_for(controller: 'dingtalk/apps', action: 'login', app_key: app_key, **host_options),
response_type: 'code',
scope: scope,
state: state,
......
json.dingtalk_user @dingtalk_user.as_json
......@@ -17,7 +17,7 @@ dd.ready(() => {
'Content-Type': 'application/json'
},
body: JSON.stringify({
corp_id: 'ding9f5ed2cec249700e35c2f4657eb6378f',
app_id: 'xxxx',
code: info.code
})
}).then(response => {
......
......@@ -11,8 +11,6 @@ Rails.application.routes.draw do
resources :apps do
collection do
post :info
end
member do
get :login
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment