forked from brandnewbox/oidc_provider
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a Rake task to generate the private key
- Loading branch information
Showing
6 changed files
with
62 additions
and
16 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
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
require "openid_connect" | ||
require "oidc_provider/engine" | ||
|
||
|
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rack/oauth2' | ||
|
||
module OIDCProvider | ||
|
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,33 @@ | ||
# frozen_string_literal: true | ||
|
||
namespace :oidc_provider do | ||
desc 'Generate the lib/oidc_provider_key.pem key file' | ||
task generate_key: :environment do | ||
key_filepath = OIDCProvider::IdToken.oidc_provider_key_path | ||
|
||
File.exist?(key_filepath) && raise("ERROR: A key file already exists at #{key_filepath}.") | ||
|
||
passphrase_env_var = OIDCProvider::IdToken::PASSPHRASE_ENV_VAR | ||
|
||
pass_phrase = ENV.fetch(passphrase_env_var, '') | ||
|
||
if pass_phrase == '' | ||
puts "\033[33mWARNING: You haven't defined a passphrase to be used to " \ | ||
'generate the new key which is concidered as insecured. You can ' \ | ||
"do it by setting the #{passphrase_env_var} environment variable " \ | ||
"and re-run this task.\033[0m" | ||
|
||
raise | ||
end | ||
|
||
key_file_content = OpenSSL::PKey::RSA.new(2048).export( | ||
OpenSSL::Cipher.new('AES-128-CBC'), | ||
pass_phrase | ||
) | ||
|
||
File.write(key_filepath, key_file_content) | ||
FileUtils.chmod(0_600, key_filepath) | ||
|
||
puts "SUCCESS: A new key file has been created at #{key_filepath}." | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.