forked from mitigate-dev/smart-id-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add rubocop and changes authentication to use API version 2
- Loading branch information
Showing
8 changed files
with
175 additions
and
88 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 |
---|---|---|
|
@@ -10,3 +10,4 @@ | |
# rspec failure tracking | ||
.rspec_status | ||
.byebug_history | ||
.idea |
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 @@ | ||
require: | ||
- rubocop | ||
- rubocop-rspec | ||
|
||
AllCops: | ||
NewCops: enable | ||
Exclude: | ||
- 'vendor/**/*' | ||
- 'spec/fixtures/**/*' | ||
- 'tmp/**/*' | ||
- '.git/**/*' | ||
- 'bin/*' | ||
- 'db/schema.rb' | ||
TargetRubyVersion: 2.7 | ||
SuggestExtensions: false | ||
|
||
Style/Documentation: | ||
Enabled: false | ||
|
||
Metrics/BlockLength: | ||
Exclude: | ||
- spec/**/*_spec.rb | ||
|
||
Metrics/MethodLength: | ||
Exclude: | ||
- 'db/**/*' | ||
Layout/EmptyLinesAroundClassBody: | ||
EnforcedStyle: empty_lines | ||
|
||
Layout/LineLength: | ||
Max: 120 | ||
|
||
Layout/SpaceAroundBlockParameters: | ||
EnforcedStyleInsidePipes: no_space | ||
|
||
Style/PercentLiteralDelimiters: | ||
PreferredDelimiters: | ||
default: [] | ||
'%i': '[]' | ||
'%I': '[]' | ||
'%r': '{}' | ||
'%w': '[]' | ||
'%W': '[]' |
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,55 +1,62 @@ | ||
require "rest-client" | ||
require "smart_id/exceptions" | ||
require "smart_id/utils/authentication_hash" | ||
require "json" | ||
|
||
module SmartId::Api | ||
module Authentication | ||
class Base | ||
attr_reader :authentication_hash | ||
|
||
def self.authenticate(**opts) | ||
new(**opts).call | ||
end | ||
# frozen_string_literal: true | ||
|
||
def initialize(**opts) | ||
@authentication_hash = opts[:authentication_hash] | ||
@display_text = opts[:display_text] | ||
@certificate_level = opts[:certificate_level] | ||
@multiple_choice = opts[:multiple_choice] | ||
end | ||
require 'rest-client' | ||
require 'smart_id/exceptions' | ||
require 'smart_id/utils/authentication_hash' | ||
require 'json' | ||
|
||
module SmartId | ||
module Api | ||
module Authentication | ||
class Base | ||
|
||
def call | ||
response = SmartId::Api::Request.execute(method: :post, uri: api_uri, params: request_params) | ||
SmartId::Api::Response.new(JSON.parse(response.body), authentication_hash) | ||
end | ||
attr_reader :authentication_hash | ||
|
||
private | ||
def self.authenticate(**opts) | ||
new(**opts).call | ||
end | ||
|
||
def request_params | ||
params = { | ||
relyingPartyUUID: SmartId.relying_party_uuid, | ||
relyingPartyName: SmartId.relying_party_name, | ||
certificateLevel: @certificate_level || SmartId.default_certificate_level, | ||
hash: authentication_hash.calculate_base64_digest, | ||
hashType: "SHA256" | ||
} | ||
def initialize(**opts) | ||
@authentication_hash = opts[:authentication_hash] | ||
@display_text = opts[:display_text] | ||
@certificate_level = opts[:certificate_level] | ||
@multiple_choice = opts[:multiple_choice] | ||
end | ||
|
||
if @display_text | ||
params.merge!(displayText: @display_text) | ||
def call | ||
response = SmartId::Api::Request.execute(method: :post, uri: api_uri, params: request_params) | ||
SmartId::Api::Response.new(JSON.parse(response.body), authentication_hash) | ||
end | ||
|
||
if @multiple_choice | ||
params.merge!(requestProperties: { vcChoice: @multiple_choice }) | ||
private | ||
|
||
def request_params | ||
params = { | ||
relyingPartyUUID: SmartId.relying_party_uuid, | ||
relyingPartyName: SmartId.relying_party_name, | ||
certificateLevel: @certificate_level || SmartId.default_certificate_level, | ||
hash: authentication_hash.calculate_base64_digest, | ||
hashType: 'SHA256', | ||
allowedInteractionsOrder: [ | ||
{ | ||
type: 'displayTextAndPIN', | ||
displayText60: 'Up to 60 characters of text here..' | ||
} | ||
] | ||
} | ||
|
||
params.merge!(displayText: @display_text) if @display_text | ||
|
||
params.merge!(requestProperties: { vcChoice: @multiple_choice }) if @multiple_choice | ||
|
||
params | ||
end | ||
|
||
params | ||
end | ||
def api_uri | ||
raise NotImplementedError | ||
end | ||
|
||
def api_uri | ||
raise NotImplementedError | ||
end | ||
end | ||
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
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