Skip to content

Commit

Permalink
parse oidc-token via post. datacite/datacite#829
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Aug 21, 2019
1 parent f6804f6 commit f60e417
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
14 changes: 6 additions & 8 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class SessionsController < ApplicationController
def create
def create_token
error_response("Wrong grant type.") && return if safe_params[:grant_type] != "password"
error_response("Missing account ID or password.") && return if
safe_params[:username].blank? || safe_params[:username] == "undefined" ||
Expand All @@ -14,16 +14,14 @@ def create
render json: { "access_token" => user.jwt, "expires_in" => 3600 * 24 * 30 }.to_json, status: 200
end

def oidc_token
credentials = request.headers["x-amzn-oidc-data"]
error_response("Missing token.") && return if credentials.blank?
def create_oidc_token
error_response("Missing token.") && return if
safe_params[:token].blank? || safe_params[:token] == "undefined"

user = User.new(credentials, type: "oidc")
user = User.new(safe_params[:token], type: "oidc")
error_response(user.errors) && return if user.errors.present?

response.set_header('access_token', user.jwt)
response.set_header('expires_in', 3600 * 24 * 30)
render plain: "OK", status: 200
render json: { "access_token" => user.jwt, "expires_in" => 3600 * 24 * 30 }.to_json, status: 200
end

def reset
Expand Down
4 changes: 2 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
root :to => 'index#index'

# authentication
post 'token', :to => 'sessions#create'
post 'token', :to => 'sessions#create_token'

# authentication via openid connect in load balancer
get 'oidc-token', :to => 'sessions#oidc_token'
post 'oidc-token', :to => 'sessions#create_oidc_token'

# send reset link
post 'reset', :to => 'sessions#reset'
Expand Down

0 comments on commit f60e417

Please sign in to comment.