Class: Kidsmin::Auth::PcoController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- Kidsmin::Auth::PcoController
- Defined in:
- app/controllers/kidsmin/auth/pco_controller.rb
Constant Summary collapse
- PCO_AUTH_URL =
"https://api.planningcenteronline.com/oauth/authorize"- PCO_TOKEN_URL =
"https://api.planningcenteronline.com/oauth/token"
Instance Method Summary collapse
Instance Method Details
#callback ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/controllers/kidsmin/auth/pco_controller.rb', line 26 def callback response = HTTParty.post(PCO_TOKEN_URL, body: { grant_type: "authorization_code", code: params[:code], client_id: Kidsmin.configuration.pco_client_id, client_secret: Kidsmin.configuration.pco_client_secret, redirect_uri: pco_callback_url }) if response.success? body = response.parsed_response integration = Kidsmin::ChurchIntegration.current integration.token_type = "oauth" integration.update_tokens!( access: body["access_token"], refresh: body["refresh_token"], expires_in: body["expires_in"] ) render plain: "PCO connected. You can close this tab." else render plain: "PCO OAuth failed: #{response.body}", status: :unprocessable_entity end end |
#connect ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/controllers/kidsmin/auth/pco_controller.rb', line 10 def connect unless Kidsmin.configuration.pco_client_id.present? render plain: "PCO Client ID not configured. Save your PCO credentials first.", status: :unprocessable_entity return end auth_params = { client_id: Kidsmin.configuration.pco_client_id, redirect_uri: pco_callback_url, response_type: "code", scope: "people check_ins calendar", state: bearer_token } redirect_to "#{PCO_AUTH_URL}?#{auth_params.to_query}", allow_other_host: true end |