Skip to content

Commit

Permalink
feat(api): Add auth information API endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
mromulus committed Mar 18, 2024
1 parent 83ee4cb commit 70e2f0d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
16 changes: 16 additions & 0 deletions app/controllers/api/v3/authinfo_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

module API
module V3
class AuthinfoController < APIController
skip_before_action :authenticate_request

def show
render json: {
issuer: Rails.configuration.oidc_issuer,
scopes: [:openid] + (Rails.configuration.authorization_mode == 'scope' ? [:resources] : [])
}
end
end
end
end
2 changes: 2 additions & 0 deletions app/views/docs/api.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ The API is using JSON format and is read-only - no altering the data in any way.
Providentia uses OpenID Connect for access management, both in web-application and API.
The authentication provider for this instance is: <%= Rails.configuration.oidc_issuer %>

Information about OpenID Connect provider can be retrieved at [/api/v3/.auth](/api/v3/.auth). It lists the URL for issuer and required scopes for current configuration.

An access token is required in order to use the API. The instructions on how to retrieve this token differ from provider to provider, but easiest method is via password grant flow.

After obtaining the access token, it should be added to the API request in `Authorization` header:
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
# API
namespace :api, defaults: { format: :json } do
namespace :v3 do
get '.auth', to: 'authinfo#show'
resources :exercises, path: '', only: %i[index show] do
resources :networks, only: %i[index]
resources :services, only: %i[index show]
Expand Down

0 comments on commit 70e2f0d

Please sign in to comment.