This repository has been archived by the owner on May 2, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Full OAuth & OIDC compliant API (#55)
Co-authored-by: Caleb Denio <[email protected]> Co-authored-by: Samuel Fernandez <[email protected]>
- Loading branch information
1 parent
ecfe247
commit 011e5e9
Showing
75 changed files
with
2,613 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"tabWidth": 2, | ||
"useTabs": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class Api::V1::ApiController < ActionController::Base #standard:disable all | ||
skip_before_action :verify_authenticity_token | ||
|
||
before_action :not_provisional | ||
|
||
private | ||
|
||
# Find the user that owns the access token | ||
def current_user | ||
User::User.find(doorkeeper_token.resource_owner_id) if doorkeeper_token | ||
end | ||
|
||
def not_provisional | ||
if doorkeeper_token.nil? | ||
return | ||
end | ||
if Doorkeeper::Application.find_by(id: doorkeeper_token.application_id).provisional? | ||
render plain: "425 Too Early - Provisional Client", status: 425 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
class Api::V1::Domains::RecordsController < Api::V1::ApiController | ||
include DomainAuthorization | ||
before_action do | ||
doorkeeper_authorize! :domains | ||
doorkeeper_authorize! :domains_records | ||
end | ||
|
||
before_action only: [:create, :update, :destroy] do | ||
doorkeeper_authorize! :domains_records_write | ||
end | ||
|
||
def index | ||
@records = current_domain.records | ||
end | ||
|
||
def create | ||
@record = Record.create(domain_id: current_domain.id, name: params["name"], type: params["type"], content: params["content"], ttl: params["ttl"], priority: params["priority"]) # standard:disable all | ||
render "show" | ||
end | ||
|
||
def show | ||
@record = Record.find(params[:id]) | ||
end | ||
|
||
def update | ||
@record = Record.find(params[:id]) | ||
|
||
(@record.type = params[:type]) if params[:type] | ||
(@record.name = params[:name]) if params[:name] | ||
(@record.content = params[:content]) if params[:content] | ||
(@record.ttl = params[:ttl]) if params[:ttl] | ||
(@record.priority = params[:priority]) if params[:priority] | ||
|
||
@record.save # standard:disable all | ||
|
||
render "show" | ||
end | ||
|
||
def destroy | ||
@record = Record.find(params[:id]) | ||
|
||
@record.destroy! #standard:disable all | ||
|
||
index | ||
render "index" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
class Api::V1::DomainsController < Api::V1::ApiController | ||
include DomainAuthorization | ||
before_action do | ||
doorkeeper_authorize! :domains | ||
end | ||
|
||
before_action only: [:create, :destroy] do | ||
doorkeeper_authorize! :domains_write | ||
end | ||
|
||
skip_before_action :authorize_domain, only: [:index, :create] | ||
|
||
def index | ||
@domains = Domain.where(user_users_id: current_user.id) | ||
if params[:records] | ||
doorkeeper_authorize!(:domains_records) | ||
end | ||
end | ||
|
||
def show | ||
@domain = Domain.find_by(host: params[:host]) | ||
if params[:records] | ||
doorkeeper_authorize!(:domains_records) | ||
end | ||
end | ||
|
||
def create | ||
@domain = Domain.new(host: params[:host], plan: params[:plan], provisional: true, user_users_id: current_user.id) | ||
if @domain.save | ||
render "show" | ||
else | ||
render json: @domain.errors, status: 418 | ||
end | ||
end | ||
|
||
def destroy | ||
@domain = Domain.find_by(host: params[:host]) | ||
@domain.destroy! | ||
|
||
index | ||
render "index" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
class Api::V1::UserController < Api::V1::ApiController | ||
before_action do | ||
doorkeeper_authorize! :user | ||
end | ||
|
||
def show | ||
if doorkeeper_token.scopes.exists?(:name) | ||
@name = current_user.name | ||
end | ||
|
||
if doorkeeper_token.scopes.exists?(:email) | ||
@email = current_user.email | ||
end | ||
|
||
@id = current_user.id | ||
@created_at = current_user.created_at | ||
@updated_at = current_user.updated_at | ||
@verified = current_user.verified | ||
|
||
if doorkeeper_token.scopes.exists?(:admin) | ||
@admin = current_user.admin | ||
end | ||
end | ||
|
||
def update | ||
redirected = false | ||
|
||
if params[:name] | ||
if doorkeeper_authorize! :name_write | ||
redirected = true | ||
else | ||
current_user.update!(name: params[:name]) | ||
end | ||
end | ||
|
||
if params[:email] | ||
if doorkeeper_authorize! :email_write | ||
redirected = true | ||
else | ||
current_user.update!(email: params[:email]) | ||
end | ||
end | ||
|
||
if !redirected | ||
show | ||
render "show" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.