Commit af617386 authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Initial addition to mimic Github OAuth calls for Jira

parent 965d87a2
class Oauth::Jira::AuthorizationsController < Doorkeeper::AuthorizationsController
skip_before_action :authenticate_resource_owner!, only: :access_token
skip_before_action :verify_authenticity_token, only: :access_token
# Overriden from Doorkeeper::AuthorizationsController to
# include the call to session.delete
def new
session[:redirect_uri] = params['redirect_uri']
redirect_to oauth_authorization_path(client_id: params['client_id'],
response_type: 'code',
redirect_uri: 'http://glgh-api-proxy.ngrok.io/jira/login/oauth/authorize_callback')
end
def callback
redirect_uri = session[:redirect_uri]
session[:redirect_uri] = nil
redirect_to(redirect_uri + '&code=' + params[:code])
end
def access_token
req_params = { client_id: params[:client_id],
client_secret: params[:client_secret],
code: params[:code],
grant_type: 'authorization_code',
redirect_uri: 'http://glgh-api-proxy.ngrok.io/jira/login/oauth/authorize_callback' }
Rails.logger.info("------ #{req_params}")
response = HTTParty.post('http://glgh-api-proxy.ngrok.io/jira/login/oauth/token', body: req_params)
token = "access_token=" + response['access_token'] + "&scope=" + response['scope'] + "&token_type=" + response['token_type']
render text: token
end
end
...@@ -19,6 +19,19 @@ Rails.application.routes.draw do ...@@ -19,6 +19,19 @@ Rails.application.routes.draw do
controllers applications: 'oauth/applications', controllers applications: 'oauth/applications',
authorized_applications: 'oauth/authorized_applications', authorized_applications: 'oauth/authorized_applications',
authorizations: 'oauth/authorizations' authorizations: 'oauth/authorizations'
end
# TODO: find a :only sort of option to generate only the routes we need
scope path: '/jira/login' do
use_doorkeeper do
controllers authorizations: 'oauth/jira/authorizations'
as authorizations: :jira_authorization
end
# Making the role of Github for Jira
get '/oauth/authorize_callback' => 'oauth/jira/authorizations#callback', as: :oauth_jira_callback
post '/oauth/access_token' => 'oauth/jira/authorizations#access_token'
end end
namespace :oauth do namespace :oauth do
......
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