Skip to content

Commit

Permalink
feat(organizations): Add gRPC token endpoint (#1263)
Browse files Browse the repository at this point in the history
Co-authored-by: Jeremy Denquin <[email protected]>
  • Loading branch information
jdenquin and jdenquin committed Aug 22, 2023
1 parent 9a8d8b3 commit 6b77883
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/controllers/api/v1/organizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ def update
end
end

def grpc_token
payload = { organization_id: current_organization.id }
grpc_token = JWT.encode(payload, ENV['SECRET_KEY_BASE'], 'HS256')

render(
json: {
organization: {
grpc_token:,
},
},
)
end

private

def input_params
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
post '/events/batch', to: 'events#batch'

put '/organizations', to: 'organizations#update'
get '/organizations/grpc_token', to: 'organizations#grpc_token'

resources :webhook_endpoints, only: %i[create index show destroy update]
resources :webhooks, only: %i[] do
Expand Down
12 changes: 12 additions & 0 deletions spec/requests/api/v1/organizations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,16 @@
end
end
end

describe 'GET /grpc_token' do
it 'returns the grpc_token' do
get_with_token(
organization,
'/api/v1/organizations/grpc_token',
)

expect(response).to have_http_status(:success)
expect(json[:organization][:grpc_token]).not_to be_nil
end
end
end

0 comments on commit 6b77883

Please sign in to comment.