emasser 1.0.3 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.env-example +2 -0
  3. data/.github/workflows/gh-pages.yml +4 -5
  4. data/.github/workflows/release.yml +9 -9
  5. data/Dockerfile +6 -4
  6. data/Gemfile +1 -1
  7. data/Gemfile.lock +25 -32
  8. data/README.md +87 -78
  9. data/docs/features.md +455 -213
  10. data/docs/images/emasser_architecture.jpg +0 -0
  11. data/emasser.gemspec +5 -3
  12. data/images/emasser_architecture.jpg +0 -0
  13. data/images/emasser_diagram-Page-3.jpg +0 -0
  14. data/lib/emasser/cli.rb +2 -2
  15. data/lib/emasser/configuration.rb +1 -0
  16. data/lib/emasser/constants.rb +11 -3
  17. data/lib/emasser/delete.rb +9 -7
  18. data/lib/emasser/get.rb +323 -49
  19. data/lib/emasser/help/cloudresource_post_mapper.md +62 -0
  20. data/lib/emasser/help/container_post_mapper.md +44 -0
  21. data/lib/emasser/output_converters.rb +101 -4
  22. data/lib/emasser/post.rb +231 -38
  23. data/lib/emasser/put.rb +23 -16
  24. data/lib/emasser/version.rb +1 -1
  25. metadata +15 -27
  26. data/.github/workflows/generate_docs.yml +0 -33
  27. data/docs/developers.md +0 -115
  28. data/docs/swagger/dist/favicon-16x16.png +0 -0
  29. data/docs/swagger/dist/favicon-32x32.png +0 -0
  30. data/docs/swagger/dist/oauth2-redirect.html +0 -75
  31. data/docs/swagger/dist/swagger-ui-bundle.js +0 -3
  32. data/docs/swagger/dist/swagger-ui-bundle.js.map +0 -1
  33. data/docs/swagger/dist/swagger-ui-es-bundle-core.js +0 -3
  34. data/docs/swagger/dist/swagger-ui-es-bundle-core.js.map +0 -1
  35. data/docs/swagger/dist/swagger-ui-es-bundle.js +0 -3
  36. data/docs/swagger/dist/swagger-ui-es-bundle.js.map +0 -1
  37. data/docs/swagger/dist/swagger-ui-standalone-preset.js +0 -3
  38. data/docs/swagger/dist/swagger-ui-standalone-preset.js.map +0 -1
  39. data/docs/swagger/dist/swagger-ui.css +0 -4
  40. data/docs/swagger/dist/swagger-ui.css.map +0 -1
  41. data/docs/swagger/dist/swagger-ui.js +0 -3
  42. data/docs/swagger/dist/swagger-ui.js.map +0 -1
  43. data/docs/swagger/index.html +0 -60
data/lib/emasser/put.rb CHANGED
@@ -129,7 +129,7 @@ module Emasser
129
129
  # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
130
130
  def update
131
131
  # Required fields
132
- body = EmassClient::ControlsRequestPutBody.new
132
+ body = EmassClient::ControlsGet.new
133
133
  body.acronym = options[:acronym]
134
134
  body.responsible_entities = options[:responsibleEntities]
135
135
  body.control_designation = options[:controlDesignation]
@@ -147,11 +147,12 @@ module Emasser
147
147
  body.impact = options[:impact] if options[:impact]
148
148
  body.impact_description = options[:impactDescription] if options[:impactDescription]
149
149
  body.residual_risk_level = options[:residualRiskLevel] if options[:residualRiskLevel]
150
+ body.test_method = options[:testMethod] if options[:testMethod]
150
151
 
151
152
  body_array = Array.new(1, body)
152
153
 
153
154
  begin
154
- result = EmassClient::ControlsApi.new.update_control_by_system_id(body_array, options[:systemId])
155
+ result = EmassClient::ControlsApi.new.update_control_by_system_id(options[:systemId], body_array)
155
156
  puts to_output_hash(result).green
156
157
  rescue EmassClient::ApiError => e
157
158
  puts 'Exception when calling ControlsApi->update_control_by_system_id'.red
@@ -268,9 +269,9 @@ module Emasser
268
269
  # Required parameters/fields
269
270
  option :systemId, type: :numeric, required: true, desc: 'A numeric value representing the system identification'
270
271
  option :poamId, type: :numeric, required: true, desc: 'A numeric value representing the poam identification'
271
- option :displayPoamId,
272
- type: :numeric, required: true,
273
- desc: 'Globally unique identifier for individual POA&M Items, seen on the front-end as "ID"'
272
+ # option :displayPoamId,
273
+ # type: :numeric, required: true,
274
+ # desc: 'Globally unique identifier for individual POA&M Items, seen on the front-end as "ID"'
274
275
  option :status, type: :string, required: true, enum: ['Ongoing', 'Risk Accepted', 'Completed', 'Not Applicable']
275
276
  option :vulnerabilityDescription, type: :string, required: true, desc: 'POA&M vulnerability description'
276
277
  option :sourceIdentVuln,
@@ -312,12 +313,13 @@ module Emasser
312
313
  # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
313
314
  def update
314
315
  # Required fields
315
- body = EmassClient::PoamRequiredPut.new
316
+ body = EmassClient::PoamGet.new
316
317
  body.poam_id = options[:poamId]
317
318
  body.status = options[:status]
318
319
  body.vulnerability_description = options[:vulnerabilityDescription]
319
320
  body.source_ident_vuln = options[:sourceIdentVuln]
320
321
  body.poc_organization = options[:pocOrganization]
322
+ body.resources = options[:resources]
321
323
 
322
324
  process_business_logic(body)
323
325
 
@@ -345,7 +347,7 @@ module Emasser
345
347
  body_array = Array.new(1, body)
346
348
 
347
349
  begin
348
- result = EmassClient::POAMApi.new.update_poam_by_system_id(body_array, options[:systemId])
350
+ result = EmassClient::POAMApi.new.update_poam_by_system_id(options[:systemId], body_array)
349
351
  puts to_output_hash(result).green
350
352
  rescue EmassClient::ApiError => e
351
353
  puts 'Exception when calling POAMApi->update_poam_by_system_id'.red
@@ -354,7 +356,7 @@ module Emasser
354
356
  end
355
357
  # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
356
358
 
357
- # rubocop:disable Metrics/BlockLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
359
+ # rubocop:disable Metrics/AbcSize, Metrics/BlockLength, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
358
360
  no_commands do
359
361
  def process_business_logic(body)
360
362
  #-----------------------------------------------------------------------------
@@ -372,13 +374,18 @@ module Emasser
372
374
  puts ' comments'.red
373
375
  puts POAMS_PUT_HELP_MESSAGE.yellow
374
376
  exit
377
+ elsif !(options[:scheduledCompletionDate].nil? && options[:milestone].nil?)
378
+ puts 'When status = "Risk Accepted" POA&M Item CAN NOT be saved with the following parameters/fields:'.red
379
+ puts ' scheduledCompletionDate, or milestone'.red
380
+ puts POAMS_PUT_HELP_MESSAGE.yellow
381
+ exit
375
382
  else
376
383
  body.comments = options[:comments]
377
384
  end
378
385
  elsif options[:status] == "Ongoing"
379
386
  if options[:scheduledCompletionDate].nil? || options[:milestone].nil?
380
387
  puts 'When status = "Ongoing" the following parameters/fields are required:'.red
381
- puts ' scheduledCompletionDate, or milestone'.red
388
+ puts ' scheduledCompletionDate, milestone'.red
382
389
  print_milestone_help
383
390
  puts POAMS_PUT_HELP_MESSAGE.yellow
384
391
  exit
@@ -457,7 +464,7 @@ module Emasser
457
464
  puts 'The milestoneId:[value] is optional, if not provided a new milestone is created'.yellow
458
465
  end
459
466
  end
460
- # rubocop:enable Metrics/BlockLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
467
+ # rubocop:enable Metrics/AbcSize, Metrics/BlockLength, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
461
468
  end
462
469
 
463
470
  # Update Milestones items to a system.
@@ -482,7 +489,7 @@ module Emasser
482
489
  type: :numeric, required: false, desc: 'The scheduled completion date - Unix time format'
483
490
 
484
491
  def update
485
- body = EmassClient::MilestonesRequestPutBody.new
492
+ body = EmassClient::MilestonesGet.new
486
493
  body.milestone_id = options[:milestoneId]
487
494
  body.description = options[:description]
488
495
  body.scheduled_completion_date = options[:scheduledCompletionDate]
@@ -490,12 +497,12 @@ module Emasser
490
497
 
491
498
  begin
492
499
  # Get milestones in one or many poa&m items in a system
493
- result = EmassClient::POAMApi
500
+ result = EmassClient::MilestonesApi
494
501
  .new
495
- .update_milestone_by_system_id_and_poam_id(body_array, options[:systemId], options[:poamId])
502
+ .update_milestone_by_system_id_and_poam_id(options[:systemId], options[:poamId], body_array)
496
503
  puts to_output_hash(result).green
497
504
  rescue EmassClient::ApiError => e
498
- puts 'Exception when calling POAMApi->update_milestone_by_system_id_and_poam_id'.red
505
+ puts 'Exception when calling MilestonesApi->update_milestone_by_system_id_and_poam_id'.red
499
506
  puts to_output_hash(e)
500
507
  end
501
508
  end
@@ -539,7 +546,7 @@ module Emasser
539
546
 
540
547
  # rubocop:disable Metrics/CyclomaticComplexity
541
548
  def update
542
- body = EmassClient::ArtifactsRequestPutBody.new
549
+ body = EmassClient::ArtifactsGet.new
543
550
  body.filename = options[:filename]
544
551
  body.type = options[:type]
545
552
  body.category = options[:category]
@@ -555,7 +562,7 @@ module Emasser
555
562
  body_array = Array.new(1, body)
556
563
 
557
564
  begin
558
- result = EmassClient::ArtifactsApi.new.update_artifact_by_system_id(body_array, options[:systemId])
565
+ result = EmassClient::ArtifactsApi.new.update_artifact_by_system_id(options[:systemId], body_array)
559
566
  puts to_output_hash(result).green
560
567
  rescue EmassClient::ApiError => e
561
568
  puts 'Exception when calling ArtifactsApi->update_artifact_by_system_id'.red
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Emasser
4
- VERSION = '1.0.3'
4
+ VERSION = '3.4.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emasser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 3.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amndeep Singh Mann
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: exe
14
14
  cert_chain: []
15
- date: 2022-01-14 00:00:00.000000000 Z
15
+ date: 2022-09-23 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: activesupport
@@ -90,14 +90,14 @@ dependencies:
90
90
  requirements:
91
91
  - - "~>"
92
92
  - !ruby/object:Gem::Version
93
- version: '1.0'
93
+ version: '3.0'
94
94
  type: :runtime
95
95
  prerelease: false
96
96
  version_requirements: !ruby/object:Gem::Requirement
97
97
  requirements:
98
98
  - - "~>"
99
99
  - !ruby/object:Gem::Version
100
- version: '1.0'
100
+ version: '3.0'
101
101
  - !ruby/object:Gem::Dependency
102
102
  name: bundler
103
103
  requirement: !ruby/object:Gem::Requirement
@@ -238,10 +238,10 @@ dependencies:
238
238
  - - "~>"
239
239
  - !ruby/object:Gem::Version
240
240
  version: '0.5'
241
- description: emasser can be used as a gem or used from the command line to access
242
- eMASS via thei API.
241
+ description: emasser can be used as a gem or used from the command line (CL) to access
242
+ eMASS endpoints via their API.
243
243
  email:
244
- - saf@mitre.org
244
+ - saf@groups.mitre.org
245
245
  executables:
246
246
  - emasser
247
247
  extensions: []
@@ -252,7 +252,6 @@ files:
252
252
  - ".github/release-drafter.yml"
253
253
  - ".github/workflows/codeql-analysis.yml"
254
254
  - ".github/workflows/draft-release.yml"
255
- - ".github/workflows/generate_docs.yml"
256
255
  - ".github/workflows/gh-pages.yml"
257
256
  - ".github/workflows/push-to-docker-mail.yml"
258
257
  - ".github/workflows/push-to-docker.yml"
@@ -271,27 +270,13 @@ files:
271
270
  - README.md
272
271
  - Rakefile
273
272
  - _config.yml
274
- - docs/developers.md
275
273
  - docs/features.md
274
+ - docs/images/emasser_architecture.jpg
276
275
  - docs/redoc/index.html
277
- - docs/swagger/dist/favicon-16x16.png
278
- - docs/swagger/dist/favicon-32x32.png
279
- - docs/swagger/dist/oauth2-redirect.html
280
- - docs/swagger/dist/swagger-ui-bundle.js
281
- - docs/swagger/dist/swagger-ui-bundle.js.map
282
- - docs/swagger/dist/swagger-ui-es-bundle-core.js
283
- - docs/swagger/dist/swagger-ui-es-bundle-core.js.map
284
- - docs/swagger/dist/swagger-ui-es-bundle.js
285
- - docs/swagger/dist/swagger-ui-es-bundle.js.map
286
- - docs/swagger/dist/swagger-ui-standalone-preset.js
287
- - docs/swagger/dist/swagger-ui-standalone-preset.js.map
288
- - docs/swagger/dist/swagger-ui.css
289
- - docs/swagger/dist/swagger-ui.css.map
290
- - docs/swagger/dist/swagger-ui.js
291
- - docs/swagger/dist/swagger-ui.js.map
292
- - docs/swagger/index.html
293
276
  - emasser.gemspec
294
277
  - exe/emasser
278
+ - images/emasser_architecture.jpg
279
+ - images/emasser_diagram-Page-3.jpg
295
280
  - lib/emasser.rb
296
281
  - lib/emasser/cli.rb
297
282
  - lib/emasser/configuration.rb
@@ -305,7 +290,9 @@ files:
305
290
  - lib/emasser/help/artifacts_del_mapper.md
306
291
  - lib/emasser/help/artifacts_post_mapper.md
307
292
  - lib/emasser/help/artifacts_put_mapper.md
293
+ - lib/emasser/help/cloudresource_post_mapper.md
308
294
  - lib/emasser/help/cmmc_get_mapper.md
295
+ - lib/emasser/help/container_post_mapper.md
309
296
  - lib/emasser/help/controls_put_mapper.md
310
297
  - lib/emasser/help/milestone_del_mapper.md
311
298
  - lib/emasser/help/milestone_post_mapper.md
@@ -325,7 +312,8 @@ files:
325
312
  homepage: https://saf.mitre.org
326
313
  licenses:
327
314
  - Apache-2.0
328
- metadata: {}
315
+ metadata:
316
+ github_repo: ssh://github.com/mitre/emasser
329
317
  post_install_message:
330
318
  rdoc_options: []
331
319
  require_paths:
@@ -341,7 +329,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
341
329
  - !ruby/object:Gem::Version
342
330
  version: '0'
343
331
  requirements: []
344
- rubygems_version: 3.2.32
332
+ rubygems_version: 3.3.7
345
333
  signing_key:
346
334
  specification_version: 4
347
335
  summary: Provide an automated capability for invoving eMASS API endpoints
@@ -1,33 +0,0 @@
1
- name: generate-docs
2
-
3
- # Run on each push to main
4
- on:
5
- push:
6
- branches: [ main ]
7
-
8
- jobs:
9
- test_job:
10
- runs-on: ubuntu-latest
11
- name: Generate Document with redoc
12
- steps:
13
- - name: Checkout
14
- uses: actions/checkout@v2
15
-
16
- # use the public name of the action
17
- - name: redoc-cli test
18
- uses: seeebiii/redoc-cli-github-action@v9
19
- with:
20
- args: 'bundle emass_client/eMASSRestOpenApi.yaml -o docs/redoc/index.html'
21
-
22
- - name: check result
23
- run: |
24
- ls -al
25
- test -f docs/redoc/index.html || (echo "Fail to generate docs/redoc/index.html from previous step." && exit 1)
26
-
27
- - name: deploy
28
- uses: peaceiris/actions-gh-pages@v3
29
- with:
30
- github_token: ${{ secrets.GITHUB_TOKEN }}
31
- publish_dir: ./docs/redoc
32
- destination_dir: docs/redoc
33
- enable_jekyll: true
data/docs/developers.md DELETED
@@ -1,115 +0,0 @@
1
- # Developers Instructions
2
-
3
- The documentation provided here is an OpenAPI (v3.0.3) Specification compliant describing, producing, consuming, and visualizing the eMASS RESTful API web services (endpoints) as described in the eMASS REST API (v3.2) document, dated October 21, 2021.
4
-
5
- The API is documented in YAML and can be viewed utilizing Swagger Editor or Visual Studio Code (VSC) with swagger and yaml extensions.
6
-
7
- ### Viewing the API via Swagger
8
-
9
- There are online tool options for viewing and editing OpenAPI compliant RESTfull APIs like the eMASS API documentations. Some of these tools are Swagger Editor or SwaggerHub. <strong>We discourage the utilization of any online capability for editing a controlled unclassified API document</strong>.
10
-
11
- To install the Swagger Editor offline from its repository follow these [instructions](https://github.com/swagger-api/swagger-editor).
12
-
13
- ### Generate the API documentation (to view in a web browser-html)
14
- eMASS API documentation can be found [here](/docs/redoc/index.html)
15
-
16
- To generate the API documentation that can be viewable in a totally dependency-free (and nice looking) HTML use the `redoc-cli` command line tool.
17
-
18
-
19
- Install the tool via `npm`:
20
- ```bash
21
- npm install -g redoc-cli
22
- ```
23
- To generate the HTML document, use the following command:
24
- ```bash
25
- redoc-cli bundle -o ./output/eMASS.html eMASSRestOpenApi.yaml
26
- ```
27
-
28
- The command above assumes that the generated file is placed in a subfolder relative to the current folder called output, and that the eMASSRestApi.yaml is in the current working directory. The generated file is called eMASS.html and can be viewed in any web browser.
29
-
30
- ### Setting up Visual Studio Code
31
- Install these Extensions (Ctrl+Shift+X):
32
- * YAML ([link](https://marketplace.visualstudio.com/items?itemName=redhat.vscode-yaml))
33
- * Swagger Viewer ([link](https://marketplace.visualstudio.com/items?itemName=Arjun.swagger-viewer))
34
- * OpenAPI Swagger Editor ([link](https://marketplace.visualstudio.com/items?itemName=42Crunch.vscode-openapi))
35
- * Swagger Snippets ([link](https://marketplace.visualstudio.com/items?itemName=adisreyaj.swagger-snippets), optional)
36
-
37
- Open the eMASS Rest API file by selecting File -> Open Folder and select the folder containing the eMASSRestApi.yaml file. Open the file into the editor and select the "OpenApi: show preview using default render" (Ctrl+K V)
38
-
39
- Once the mock server is running, we can utilize the "Try it Out" on each of the API endpoints to test the API documentation with mock data.
40
-
41
- ### Using PRISM HTTP mock Server
42
- Install prism (if not installed) via npm:
43
- ``` npm
44
- npm install -g @stoplight/prism-cli
45
- ```
46
-
47
- Run the prism server on the localhost, use the -p parameter to set the port (using 4010)
48
- ``` node
49
- prism mock -p 4010 eMASSRestOpenApi.yaml
50
- ```
51
-
52
- To invoke the mock server interactive use the -d parameter (provides fake responses using x-faker)
53
- ``` node
54
- prism mock -d -p 4010 eMASSRestOpenAPI.yaml
55
- ```
56
- **Note:**
57
- * The Prism starting commands above assumes that the current path contains the eMASSRestAPI.yaml file
58
- * If using VSC, Prism restarts automatically when the yaml file is modified and saved
59
- * Use `npx` instead of `npm` to install packages locally, but still be able to run them as if they were global
60
-
61
- Now you can access the fake API endpoints utilizing either CURL or the Swagger Editor. The following curl command invokes the systems endpoint with a path parameter of policy=rmf:
62
- ``` node
63
- curl -X GET "http://localhost:4010/api/systems?policy=rmf" -H "accept: application/json" -H "api-key: f32516cc-57d3-43f5-9e16-8f86780a4cce" -H "user-uid: 1647389405"
64
- ```
65
- Note: The API expects the api-key and user-uid headers.
66
-
67
- ## Swagger Codegen
68
- ### Clone the source code
69
- Follow these instruction to generate the eMASS client API library (software development kit - SDK):
70
- ``` git
71
- git clone https://github.com/swagger-api/swagger-codegen
72
- cd swagger-codegen
73
- git checkout 3.0.0
74
- mvn clean package
75
- ```
76
- Alternatively, you can follow instruction listed in [Swagger Codegen](https://github.com/swagger-api/swagger-codegen/tree/3.0.0#getting-started). The eMASS API utilized the OpenAPI version 3.0 standards, ensure that the proper `Swagger Codegen` is utilized to generate the client SDK.
77
-
78
-
79
- ### Build the Client SDK
80
-
81
- NOTE: The current [handlebar templates](https://github.com/swagger-api/swagger-codegen/tree/3.0.0#modifying-the-client-library-format) do not provide a configuration variable where a keypassword can be defined containing the client certificate passphrase used by libcurl wrapper Typhoeus. For this reason, we have provided [updated templates](./swagger-codegen/ruby_template) that can be utilized in the interim until the necessary fixes are integrated into the [main repository](https://github.com/swagger-api/swagger-codegen/tree/3.0.0)
82
-
83
- After cloning the appropriate `Swagger Codegen` baseline (3.0.0) generate the SDK (make sure you are in the cloned directory, e.g; /path/to/codegen/swagger-codegen)
84
-
85
- To generate the client SDK with provided templates use:
86
- ``` node
87
- java -jar swagger-codegen-cli generate generate -i /path/to/yaml/eMASSRestOpenApi.yaml -l ruby -t emass_client/swagger-codegen/ruby_template -o /path/to/sdk/emass_api_client
88
- ```
89
-
90
-
91
- To generate without specifying the templates use:
92
- ``` node
93
- java -jar swagger-codegen-cli generate -i /path/to/yaml/eMASSRestOpenApi.yaml -l ruby -o /path/to/sdk/emass_api_client
94
- ```
95
- Note: The command listed above is for generating a ruby client SDK. Other languages are available, see instructions [here](https://github.com/swagger-api/swagger-codegen/tree/3.0.0#to-generate-a-sample-client-library)
96
-
97
- ## Ruby Client
98
- Information about the swagger generated ruby client SDK refer to the [ruby_client](./ruby_client) directory.
99
-
100
-
101
- ---
102
-
103
- NOTICE
104
-
105
- © 2020 The MITRE Corporation.
106
-
107
- Approved for Public Release; Distribution Unlimited. Case Number 18-3678.
108
- NOTICE
109
-
110
- MITRE hereby grants express written permission to use, reproduce, distribute, modify, and otherwise leverage this software to the extent permitted by the licensed terms provided in the LICENSE.md file included with this project.
111
- NOTICE
112
-
113
- This software was produced for the U. S. Government under Contract Number HHSM-500-2012-00008I, and is subject to Federal Acquisition Regulation Clause 52.227-14, Rights in Data-General.
114
-
115
- No other use other than that granted to the U. S. Government, or to those acting on behalf of the U. S. Government under that Clause is authorized without the express written permission of The MITRE Corporation. DISA STIGs are published by DISA, see: https://public.cyber.mil/privacy-security/
Binary file
Binary file
@@ -1,75 +0,0 @@
1
- <!doctype html>
2
- <html lang="en-US">
3
- <head>
4
- <title>Swagger UI: OAuth2 Redirect</title>
5
- </head>
6
- <body>
7
- <script>
8
- 'use strict';
9
- function run () {
10
- var oauth2 = window.opener.swaggerUIRedirectOauth2;
11
- var sentState = oauth2.state;
12
- var redirectUrl = oauth2.redirectUrl;
13
- var isValid, qp, arr;
14
-
15
- if (/code|token|error/.test(window.location.hash)) {
16
- qp = window.location.hash.substring(1);
17
- } else {
18
- qp = location.search.substring(1);
19
- }
20
-
21
- arr = qp.split("&");
22
- arr.forEach(function (v,i,_arr) { _arr[i] = '"' + v.replace('=', '":"') + '"';});
23
- qp = qp ? JSON.parse('{' + arr.join() + '}',
24
- function (key, value) {
25
- return key === "" ? value : decodeURIComponent(value);
26
- }
27
- ) : {};
28
-
29
- isValid = qp.state === sentState;
30
-
31
- if ((
32
- oauth2.auth.schema.get("flow") === "accessCode" ||
33
- oauth2.auth.schema.get("flow") === "authorizationCode" ||
34
- oauth2.auth.schema.get("flow") === "authorization_code"
35
- ) && !oauth2.auth.code) {
36
- if (!isValid) {
37
- oauth2.errCb({
38
- authId: oauth2.auth.name,
39
- source: "auth",
40
- level: "warning",
41
- message: "Authorization may be unsafe, passed state was changed in server Passed state wasn't returned from auth server"
42
- });
43
- }
44
-
45
- if (qp.code) {
46
- delete oauth2.state;
47
- oauth2.auth.code = qp.code;
48
- oauth2.callback({auth: oauth2.auth, redirectUrl: redirectUrl});
49
- } else {
50
- let oauthErrorMsg;
51
- if (qp.error) {
52
- oauthErrorMsg = "["+qp.error+"]: " +
53
- (qp.error_description ? qp.error_description+ ". " : "no accessCode received from the server. ") +
54
- (qp.error_uri ? "More info: "+qp.error_uri : "");
55
- }
56
-
57
- oauth2.errCb({
58
- authId: oauth2.auth.name,
59
- source: "auth",
60
- level: "error",
61
- message: oauthErrorMsg || "[Authorization failed]: no accessCode received from the server"
62
- });
63
- }
64
- } else {
65
- oauth2.callback({auth: oauth2.auth, token: qp, isValid: isValid, redirectUrl: redirectUrl});
66
- }
67
- window.close();
68
- }
69
-
70
- window.addEventListener('DOMContentLoaded', function () {
71
- run();
72
- });
73
- </script>
74
- </body>
75
- </html>