-
Notifications
You must be signed in to change notification settings - Fork 0
implement oidc as a new provider #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0482093
implement oidc as a new provider
Knerio 3f7e96f
extend readme
Knerio f2d5b57
fix wrong config key
Knerio d36840e
add template string to auth url
Knerio e55461b
fix too long line
Knerio a38fc2b
Merge branch 'main' into providers/oidc
Knerio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -10,6 +10,7 @@ OAuth: | |
- Microsoft | ||
- Github | ||
- Gitlab | ||
- OIDC / oAuth2 | ||
|
||
## Installation | ||
|
||
|
This file contains hidden or 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 hidden or 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,63 @@ | ||
# frozen_string_literal: true | ||
|
||
module Code0 | ||
module Identities | ||
module Provider | ||
class Oidc < BaseOauth | ||
def token_url | ||
config[:token_url] | ||
end | ||
|
||
def token_payload(code) | ||
{ code: code, | ||
grant_type: "authorization_code", | ||
redirect_uri: config[:redirect_uri], | ||
client_id: config[:client_id], | ||
client_secret: config[:client_secret] } | ||
end | ||
|
||
def user_details_url | ||
config[:user_details_url] | ||
end | ||
|
||
def authorization_url | ||
config[:user_details_url] | ||
end | ||
|
||
def create_identity(response, *) | ||
body = response.parsed_response | ||
|
||
Identity.new(config[:provider_name], | ||
find_attribute(body, config[:attribute_statements][:identifier]), | ||
find_attribute(body, config[:attribute_statements][:username]), | ||
find_attribute(body, config[:attribute_statements][:email]), | ||
find_attribute(body, config[:attribute_statements][:firstname]), | ||
find_attribute(body, config[:attribute_statements][:lastname])) | ||
end | ||
|
||
def config | ||
config = super | ||
|
||
# rubocop:disable Layout/LineLength | ||
config[:provider_name] ||= :oidc | ||
config[:attribute_statements] ||= {} | ||
config[:attribute_statements][:identifier] ||= %w[sub id identifier] | ||
config[:attribute_statements][:username] ||= %w[username name login] | ||
config[:attribute_statements][:email] ||= %w[email mail] | ||
config[:attribute_statements][:firstname] ||= %w[first_name firstname firstName givenname given_name givenName] | ||
config[:attribute_statements][:lastname] ||= %w[last_name lastname lastName family_name familyName familyname] | ||
# rubocop:enable Layout/LineLength | ||
|
||
config | ||
end | ||
|
||
def find_attribute(attributes, attribute_statements) | ||
attribute_statements.each do |statement| | ||
return attributes[statement] unless attributes[statement].nil? | ||
end | ||
nil | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains hidden or 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,17 @@ | ||
module Code0 | ||
module Identities | ||
module Provider | ||
class Oidc < BaseOauth | ||
def token_url: () -> String | ||
|
||
def token_payload: (code: String) -> { code: String, grant_type: "authorization_code", redirect_uri: String, client_id: String, client_secret: String } | ||
|
||
def user_details_url: () -> String | ||
|
||
def authorization_url: () -> String | ||
|
||
def create_identity: (response: Net::HTTPResponse) -> Identity | ||
end | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.