minty 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.bundle/config +4 -0
- data/.devcontainer/Dockerfile +19 -0
- data/.devcontainer/devcontainer.json +37 -0
- data/.env.example +2 -0
- data/.gemrelease +2 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +33 -0
- data/.github/dependabot.yml +10 -0
- data/.github/stale.yml +20 -0
- data/.gitignore +18 -0
- data/.rspec +3 -0
- data/.rubocop.yml +9 -0
- data/CODE_OF_CONDUCT.md +3 -0
- data/DEPLOYMENT.md +61 -0
- data/DEVELOPMENT.md +35 -0
- data/Dockerfile +5 -0
- data/EXAMPLES.md +195 -0
- data/Gemfile +21 -0
- data/Gemfile.lock +250 -0
- data/Guardfile +39 -0
- data/LICENSE +21 -0
- data/Makefile +5 -0
- data/README.md +88 -0
- data/RUBYGEM.md +9 -0
- data/Rakefile +33 -0
- data/codecov.yml +22 -0
- data/lib/minty/algorithm.rb +7 -0
- data/lib/minty/api/authentication_endpoints.rb +30 -0
- data/lib/minty/api/v2.rb +8 -0
- data/lib/minty/client.rb +7 -0
- data/lib/minty/exception.rb +50 -0
- data/lib/minty/mixins/api_token_struct.rb +4 -0
- data/lib/minty/mixins/headers.rb +19 -0
- data/lib/minty/mixins/httpproxy.rb +125 -0
- data/lib/minty/mixins/initializer.rb +38 -0
- data/lib/minty/mixins/validation.rb +113 -0
- data/lib/minty/mixins.rb +23 -0
- data/lib/minty/version.rb +5 -0
- data/lib/minty.rb +11 -0
- data/lib/minty_client.rb +4 -0
- data/minty.gemspec +39 -0
- data/publish_rubygem.sh +10 -0
- data/spec/integration/lib/minty/api/api_authentication_spec.rb +122 -0
- data/spec/integration/lib/minty/minty_client_spec.rb +92 -0
- data/spec/lib/minty/client_spec.rb +223 -0
- data/spec/lib/minty/mixins/httpproxy_spec.rb +658 -0
- data/spec/lib/minty/mixins/initializer_spec.rb +121 -0
- data/spec/lib/minty/mixins/token_management_spec.rb +129 -0
- data/spec/lib/minty/mixins/validation_spec.rb +559 -0
- data/spec/spec_helper.rb +75 -0
- data/spec/support/credentials.rb +14 -0
- data/spec/support/dummy_class.rb +20 -0
- data/spec/support/dummy_class_for_proxy.rb +6 -0
- data/spec/support/dummy_class_for_restclient.rb +4 -0
- data/spec/support/dummy_class_for_tokens.rb +18 -0
- data/spec/support/import_users.json +13 -0
- data/spec/support/stub_response.rb +3 -0
- metadata +366 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7c4937d043506771b524e4ca14acfcf5fa30bcd141b2a0e6bb6cbb16840bd845
|
4
|
+
data.tar.gz: 4da3f2a001aa8633abe790d90669e159642245cb42b199855836cdf8e7e00851
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 600c76679a2131f77221338fcfe3e54d9a4a335ddbb9ec7cb0d2bbf4fbafff5c051c67d3e067444f9cf7bee31edb621ae724077475d349d6602b7edd4932a691
|
7
|
+
data.tar.gz: 00c0acd3dd87c681ba0af9abc7248b53d80c0afb5f0cc6e7171d3fe4eba84acc3762c596a447b2b3ea526c0a410debd25ea342ce49c0c47e3069fc23058e4f65
|
data/.bundle/config
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/ruby/.devcontainer/base.Dockerfile
|
2
|
+
|
3
|
+
# [Choice] Ruby version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.1, 3.0, 2, 2.7, 3-bullseye, 3.1-bullseye, 3.0-bullseye, 2-bullseye, 2.7-bullseye, 3-buster, 3.1-buster, 3.0-buster, 2-buster, 2.7-buster
|
4
|
+
ARG VARIANT="3.1-bullseye"
|
5
|
+
FROM mcr.microsoft.com/vscode/devcontainers/ruby:0-${VARIANT}
|
6
|
+
|
7
|
+
# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
|
8
|
+
ARG NODE_VERSION="none"
|
9
|
+
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi
|
10
|
+
|
11
|
+
# [Optional] Uncomment this section to install additional OS packages.
|
12
|
+
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
|
13
|
+
# && apt-get -y install --no-install-recommends <your-package-list-here>
|
14
|
+
|
15
|
+
# [Optional] Uncomment this line to install additional gems.
|
16
|
+
# RUN gem install <your-gem-names-here>
|
17
|
+
|
18
|
+
# [Optional] Uncomment this line to install global node packages.
|
19
|
+
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1
|
@@ -0,0 +1,37 @@
|
|
1
|
+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
|
2
|
+
// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/ruby
|
3
|
+
{
|
4
|
+
"name": "Ruby",
|
5
|
+
"build": {
|
6
|
+
"dockerfile": "Dockerfile",
|
7
|
+
"args": {
|
8
|
+
// Update 'VARIANT' to pick a Ruby version: 3, 3.1, 3.0, 2, 2.7
|
9
|
+
// Append -bullseye or -buster to pin to an OS version.
|
10
|
+
// Use -bullseye variants on local on arm64/Apple Silicon.
|
11
|
+
"VARIANT": "3.1",
|
12
|
+
// Options
|
13
|
+
"NODE_VERSION": "lts/*"
|
14
|
+
}
|
15
|
+
},
|
16
|
+
|
17
|
+
// Configure tool-specific properties.
|
18
|
+
"customizations": {
|
19
|
+
// Configure properties specific to VS Code.
|
20
|
+
"vscode": {
|
21
|
+
// Add the IDs of extensions you want installed when the container is created.
|
22
|
+
"extensions": [
|
23
|
+
"rebornix.Ruby"
|
24
|
+
]
|
25
|
+
}
|
26
|
+
},
|
27
|
+
|
28
|
+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
29
|
+
// "forwardPorts": [],
|
30
|
+
|
31
|
+
// Use 'postCreateCommand' to run commands after the container is created.
|
32
|
+
// "postCreateCommand": "ruby --version",
|
33
|
+
|
34
|
+
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
|
35
|
+
"remoteUser": "vscode"
|
36
|
+
|
37
|
+
}
|
data/.env.example
ADDED
data/.gemrelease
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
### Changes
|
2
|
+
|
3
|
+
Please describe both what is changing and why this is important. Include:
|
4
|
+
|
5
|
+
- Endpoints added, deleted, deprecated, or changed
|
6
|
+
- Classes and methods added, deleted, deprecated, or changed
|
7
|
+
- Screenshots of new or changed UI, if applicable
|
8
|
+
- A summary of usage if this is a new feature or change to a public API (this should also be added to relevant documentation once released)
|
9
|
+
|
10
|
+
### References
|
11
|
+
|
12
|
+
Please include relevant links supporting this change such as a:
|
13
|
+
|
14
|
+
- support ticket
|
15
|
+
- community post
|
16
|
+
- StackOverflow post
|
17
|
+
- support forum thread
|
18
|
+
|
19
|
+
Please note any links that are not publicly accessible.
|
20
|
+
|
21
|
+
### Testing
|
22
|
+
|
23
|
+
Please describe how this can be tested by reviewers. Be specific about anything not tested and reasons why. If this library has unit and/or integration testing, tests should be added for new functionality and existing tests should complete without errors.
|
24
|
+
|
25
|
+
* [ ] This change adds unit test coverage
|
26
|
+
* [ ] This change adds integration test coverage
|
27
|
+
* [ ] This change has been tested on the latest version of Ruby
|
28
|
+
|
29
|
+
### Checklist
|
30
|
+
|
31
|
+
* [ ] All existing and new tests complete without errors
|
32
|
+
* [ ] Rubocop passes on all added/modified files
|
33
|
+
* [ ] All active GitHub checks have passed
|
data/.github/stale.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# Configuration for probot-stale - https://github.com/probot/stale
|
2
|
+
|
3
|
+
# Number of days of inactivity before an Issue or Pull Request becomes stale
|
4
|
+
daysUntilStale: 90
|
5
|
+
|
6
|
+
# Number of days of inactivity before an Issue or Pull Request with the stale label is closed.
|
7
|
+
daysUntilClose: 7
|
8
|
+
|
9
|
+
# Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable
|
10
|
+
exemptLabels: []
|
11
|
+
|
12
|
+
# Set to true to ignore issues with an assignee (defaults to false)
|
13
|
+
exemptAssignees: true
|
14
|
+
|
15
|
+
# Label to use when marking as stale
|
16
|
+
staleLabel: closed:stale
|
17
|
+
|
18
|
+
# Comment to post when marking as stale. Set to `false` to disable
|
19
|
+
markComment: >
|
20
|
+
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you have not received a response for our team (apologies for the delay) and this is still a blocker, please reply with additional information or just a ping. Thank you for your contribution! 🙇♂️
|
data/.gitignore
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
bin/
|
2
|
+
!examples/ruby-on-rails-api/bin/
|
3
|
+
vendor/
|
4
|
+
doc/
|
5
|
+
.DS_Store
|
6
|
+
.ruby-version
|
7
|
+
coverage
|
8
|
+
*.gem
|
9
|
+
.ruby-gemset
|
10
|
+
*.swp
|
11
|
+
*.swo
|
12
|
+
spec/minty.yml
|
13
|
+
.env
|
14
|
+
/.yardoc/checksums
|
15
|
+
/.yardoc/complete
|
16
|
+
/.yardoc/object_types
|
17
|
+
/.yardoc/objects/root.dat
|
18
|
+
/.yardoc/proxy_types
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
data/DEPLOYMENT.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# Releasing the gem
|
2
|
+
|
3
|
+
## Credentials set up
|
4
|
+
|
5
|
+
Make sure you have access in https://rubygems.org/gems/minty/ and that your Ruby Gems tokens are set in `~/.gem/credentials`.
|
6
|
+
|
7
|
+
In order to generate the required changelog entry, define an environment variable `GITHUB_READ_TOKEN` with a Github API token that has READ access to `repo:public_repo`. You can generate a Github API Token [here](https://github.com/settings/tokens/new?description=GitHub%20Changelog%20Generator%20token).
|
8
|
+
|
9
|
+
Create a new Github Milestone with the version name prefixed with `v`. i.e. `v4.10.2`. Assign every Issue and Pull Request to be included on this release to that Milestone, and tag them with the `CH:xxxxxx` labels, depending on the type of change fixed or introduced there.
|
10
|
+
|
11
|
+
Finally, follow the next steps:
|
12
|
+
|
13
|
+
```bash
|
14
|
+
# Install gems for exec commands
|
15
|
+
bundle install
|
16
|
+
|
17
|
+
# Run all tests
|
18
|
+
bundle exec rake test
|
19
|
+
|
20
|
+
# Create a release branch
|
21
|
+
git checkout master
|
22
|
+
git pull
|
23
|
+
git checkout -b release-X.X.X
|
24
|
+
git push --set-upstream origin release-X.X.X
|
25
|
+
|
26
|
+
# Update the version number
|
27
|
+
# This will create a commit with the new version
|
28
|
+
bundle exec gem bump --version X.X.X
|
29
|
+
|
30
|
+
# Make sure the Gemfile.lock is up-to-date
|
31
|
+
bundle update
|
32
|
+
git commit -am "Update gems"
|
33
|
+
|
34
|
+
# Generate the changelog
|
35
|
+
github_changelog_generator -t $GITHUB_READ_TOKEN
|
36
|
+
# ... or similar.
|
37
|
+
# Review the changelog
|
38
|
+
# Remove "unreleased" section
|
39
|
+
# Make sure the tags are ordered
|
40
|
+
|
41
|
+
# Commit, push, and create a PR for this release
|
42
|
+
git commit -am "Update CHANGELOG.md"
|
43
|
+
git push
|
44
|
+
|
45
|
+
# Add related milestone
|
46
|
+
# Create PR on GitHub and assign for review
|
47
|
+
# Merge/rebase and delete branch once approved
|
48
|
+
|
49
|
+
# Create and add a tag
|
50
|
+
git checkout master
|
51
|
+
git pull
|
52
|
+
bundle exec gem tag
|
53
|
+
git push origin vX.X.X
|
54
|
+
# Create a new release from this tag on GitHub using markdown from the changelog
|
55
|
+
|
56
|
+
# Make sure you are an author for this gem here https://rubygems.org/gems/minty/
|
57
|
+
# Rubygems token can be updated in ~/.gem/credentials
|
58
|
+
bundle exec gem release
|
59
|
+
```
|
60
|
+
|
61
|
+
The steps above were tested with Ruby `v2.5.7`.
|
data/DEVELOPMENT.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Development
|
2
|
+
|
3
|
+
In order to set up the local environment you'd have to have Ruby installed and a few global gems used to run and record the unit tests. A working Ruby version can be taken from the [CI script](/.circleci/config.yml). At the moment of this writting we're using Ruby `2.5.7`.
|
4
|
+
|
5
|
+
> It is expected that every Pull Request introducing a fix, change or feature contains enough test coverage to assert the new behavior.
|
6
|
+
|
7
|
+
## Running the tests
|
8
|
+
|
9
|
+
Install the gems required for this project.
|
10
|
+
|
11
|
+
```bash
|
12
|
+
bundle install
|
13
|
+
```
|
14
|
+
|
15
|
+
Finally, run the tests.
|
16
|
+
|
17
|
+
```bash
|
18
|
+
bundle exec rake test
|
19
|
+
```
|
20
|
+
|
21
|
+
### Running only unit tests
|
22
|
+
|
23
|
+
You can run only the unit tests and ignore the integration tests by running the following:
|
24
|
+
|
25
|
+
```bash
|
26
|
+
bundle exec rake spec
|
27
|
+
```
|
28
|
+
|
29
|
+
### Running only integration tests
|
30
|
+
|
31
|
+
You can run only the unit tests and ignore the integration tests by running the following:
|
32
|
+
|
33
|
+
```bash
|
34
|
+
bundle exec rake integration
|
35
|
+
```
|
data/Dockerfile
ADDED
data/EXAMPLES.md
ADDED
@@ -0,0 +1,195 @@
|
|
1
|
+
# Examples using ruby
|
2
|
+
|
3
|
+
## Build a URL to Universal Login Page
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
require 'minty'
|
7
|
+
|
8
|
+
client = MintyClient.new(
|
9
|
+
client_id: ENV['AUTH0_RUBY_CLIENT_ID'],
|
10
|
+
client_secret: ENV['AUTH0_RUBY_CLIENT_SECRET'],
|
11
|
+
domain: ENV['AUTH0_RUBY_DOMAIN'],
|
12
|
+
)
|
13
|
+
|
14
|
+
client.authorize_url 'http://localhost:3000'
|
15
|
+
|
16
|
+
> => #<URI::HTTPS https://YOUR_DOMAIN/authorize?client_id=YOUR_CLIENT_ID&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A3000>
|
17
|
+
|
18
|
+
```
|
19
|
+
|
20
|
+
## Management API Client
|
21
|
+
|
22
|
+
As a simple example of how to get started with the management API, we'll create an admin route to point to a list of all users from Minty:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
# config/routes.rb
|
26
|
+
Rails.application.routes.draw do
|
27
|
+
# ...
|
28
|
+
get 'admin/users', to: 'all_users#index'
|
29
|
+
# ...
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
... and a Controller to handle that route:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
# app/controllers/all_users_controller.rb
|
37
|
+
require 'minty'
|
38
|
+
|
39
|
+
class AllUsersController < ApplicationController
|
40
|
+
# Get all users from Minty with "minty" in their email.
|
41
|
+
def index
|
42
|
+
@params = {
|
43
|
+
q: "email:*minty*",
|
44
|
+
fields: 'email,user_id,name',
|
45
|
+
include_fields: true,
|
46
|
+
page: 0,
|
47
|
+
per_page: 50
|
48
|
+
}
|
49
|
+
@users = minty_client.users @params
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
# Setup the Minty API connection.
|
55
|
+
def minty_client
|
56
|
+
@minty_client ||= MintyClient.new(
|
57
|
+
client_id: ENV['AUTH0_RUBY_CLIENT_ID'],
|
58
|
+
client_secret: ENV['AUTH0_RUBY_CLIENT_SECRET'],
|
59
|
+
domain: ENV['AUTH0_RUBY_DOMAIN'],
|
60
|
+
api_version: 2,
|
61
|
+
timeout: 15 # optional, defaults to 10
|
62
|
+
)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
```
|
66
|
+
|
67
|
+
In this example, we're using environment variables to store the values needed to connect to Minty and authorize. The `token` used above is an API token for the Management API with the scopes required to perform a specific action (in this case `read:users`). These tokens can be [generated manually](https://minty.page/docs/api/management/v2/tokens#get-a-token-manually) using a test Application or with the [Application](https://manage.minty.page/#/applications) being used for your project.
|
68
|
+
|
69
|
+
Finally, we'll add a view to display the results:
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
# app/views/all_users/index.html.erb
|
73
|
+
<h1>Users</h1>
|
74
|
+
<%= debug @params %>
|
75
|
+
<%= debug @users %>
|
76
|
+
```
|
77
|
+
|
78
|
+
This should show the parameters passed to the `users` method and a list of users that matched the query (or an empty array if none).
|
79
|
+
|
80
|
+
## Organizations
|
81
|
+
|
82
|
+
[Organizations](https://minty.page/docs/organizations) is a set of features that provide better support for developers who build and maintain SaaS and Business-to-Business (B2B) applications.
|
83
|
+
|
84
|
+
Note that Organizations is currently only available to customers on our Enterprise and Startup subscription plans.
|
85
|
+
|
86
|
+
### Logging in with an Organization
|
87
|
+
|
88
|
+
Configure the Authentication API client and pass your Organization ID to the authorize url:
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
require 'minty'
|
92
|
+
|
93
|
+
@minty_client ||= MintyClient.new(
|
94
|
+
client_id: '{YOUR_APPLICATION_CLIENT_ID}',
|
95
|
+
client_secret: '{YOUR_APPLICATION_CLIENT_SECRET}',
|
96
|
+
domain: '{YOUR_TENANT}.minty.page',
|
97
|
+
organization: "{YOUR_ORGANIZATION_ID}"
|
98
|
+
)
|
99
|
+
|
100
|
+
universal_login_url = @minty_client.authorization_url("https://{YOUR_APPLICATION_CALLBACK_URL}")
|
101
|
+
|
102
|
+
# redirect_to universal_login_url
|
103
|
+
```
|
104
|
+
|
105
|
+
### Accepting user invitations
|
106
|
+
|
107
|
+
Minty Organizations allow users to be invited using emailed links, which will direct a user back to your application. The URL the user will arrive at is based on your configured `Application Login URI`, which you can change from your Application's settings inside the Minty dashboard. When they arrive at this URL, a `invitation` and `organization` query parameters will be provided
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
require 'minty'
|
111
|
+
|
112
|
+
@minty_client ||= MintyClient.new(
|
113
|
+
client_id: '{YOUR_APPLICATION_CLIENT_ID}',
|
114
|
+
client_secret: '{YOUR_APPLICATION_CLIENT_ID}',
|
115
|
+
domain: '{YOUR_TENANT}.minty.page',
|
116
|
+
organization: "{YOUR_ORGANIZATION_ID}"
|
117
|
+
)
|
118
|
+
|
119
|
+
universal_login_url = @minty_client.authorization_url("https://{YOUR_APPLICATION_CALLBACK_URL}", {
|
120
|
+
organization: "{ORGANIZATION_QUERY_PARAM}", # You can override organization if needed
|
121
|
+
invitation: "{INVITATION_QUERY_PARAM}"
|
122
|
+
})
|
123
|
+
|
124
|
+
# redirect_to universal_login_url
|
125
|
+
```
|
126
|
+
|
127
|
+
## ID Token Validation
|
128
|
+
|
129
|
+
An ID token may be present in the credentials received after authentication. This token contains information associated with the user that has just logged in, provided the scope used contained `openid`. You can [read more about ID tokens here](https://minty.page/docs/tokens/concepts/id-tokens).
|
130
|
+
|
131
|
+
Before accessing its contents, you must first validate the ID token to ensure it has not been tampered with and that it is meant for your application to consume. Use the `validate_id_token` method to do so:
|
132
|
+
|
133
|
+
```ruby
|
134
|
+
begin
|
135
|
+
@minty_client.validate_id_token 'YOUR_ID_TOKEN'
|
136
|
+
rescue Minty::InvalidIdToken => e
|
137
|
+
# In this case the ID Token contents should not be trusted
|
138
|
+
end
|
139
|
+
```
|
140
|
+
|
141
|
+
The method takes the following optional keyword parameters:
|
142
|
+
|
143
|
+
| Parameter | Type | Description | Default value |
|
144
|
+
| -------------- | -------------- | ------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
|
145
|
+
| `algorithm` | `JWTAlgorithm` | The [signing algorithm](https://minty.page/docs/tokens/concepts/signing-algorithms) used by your Minty application. | `Minty::Algorithm::RS256` (using the [JWKS URL](https://minty.page/docs/tokens/concepts/jwks) of your **Minty Domain**) |
|
146
|
+
| `leeway` | Integer | Number of seconds to account for clock skew when validating the `exp`, `iat` and `azp` claims. | `60` |
|
147
|
+
| `nonce` | String | The `nonce` value you sent in the call to `/authorize`, if any. | `nil` |
|
148
|
+
| `max_age` | Integer | The `max_age` value you sent in the call to `/authorize`, if any. | `nil` |
|
149
|
+
| `issuer` | String | By default the `iss` claim will be checked against the URL of your **Minty Domain**. Use this parameter to override that. | `nil` |
|
150
|
+
| `audience` | String | By default the `aud` claim will be compared to your **Minty Client ID**. Use this parameter to override that. | `nil` |
|
151
|
+
| `organization` | String | By default the `org_id` claim will be compared to your **Organization ID**. Use this parameter to override that. | `nil` |
|
152
|
+
|
153
|
+
You can check the signing algorithm value under **Advanced Settings > OAuth > JsonWebToken Signature Algorithm** in your Minty application settings panel. [We recommend](https://minty.page/docs/tokens/concepts/signing-algorithms#our-recommendation) that you make use of asymmetric signing algorithms like `RS256` instead of symmetric ones like `HS256`.
|
154
|
+
|
155
|
+
```ruby
|
156
|
+
# HS256
|
157
|
+
|
158
|
+
begin
|
159
|
+
@minty_client.validate_id_token 'YOUR_ID_TOKEN', algorithm: Minty::Algorithm::HS256.secret('YOUR_SECRET')
|
160
|
+
rescue Minty::InvalidIdToken => e
|
161
|
+
# Handle error
|
162
|
+
end
|
163
|
+
|
164
|
+
# RS256 with a custom JWKS URL
|
165
|
+
|
166
|
+
begin
|
167
|
+
@minty_client.validate_id_token 'YOUR_ID_TOKEN', algorithm: Minty::Algorithm::RS256.jwks_url('YOUR_URL')
|
168
|
+
rescue Minty::InvalidIdToken => e
|
169
|
+
# Handle error
|
170
|
+
end
|
171
|
+
```
|
172
|
+
|
173
|
+
### Organization ID Token Validation
|
174
|
+
|
175
|
+
If an org_id claim is present in the Access Token, then the claim should be validated by the API to ensure that the value received is expected or known.
|
176
|
+
|
177
|
+
In particular:
|
178
|
+
|
179
|
+
- The issuer (iss) claim should be checked to ensure the token was issued by Minty
|
180
|
+
|
181
|
+
- the org_id claim should be checked to ensure it is a value that is already known to the application. This could be validated against a known list of organization IDs, or perhaps checked in conjunction with the current request URL. e.g. the sub-domain may hint at what organization should be used to validate the Access Token.
|
182
|
+
|
183
|
+
Normally, validating the issuer would be enough to ensure that the token was issued by Minty. In the case of organizations, additional checks should be made so that the organization within an Minty tenant is expected.
|
184
|
+
|
185
|
+
If the claim cannot be validated, then the application should deem the token invalid.
|
186
|
+
|
187
|
+
```ruby
|
188
|
+
begin
|
189
|
+
@minty_client.validate_id_token 'YOUR_ID_TOKEN', organization: '{Expected org_id}'
|
190
|
+
rescue Minty::InvalidIdToken => e
|
191
|
+
# In this case the ID Token contents should not be trusted
|
192
|
+
end
|
193
|
+
```
|
194
|
+
|
195
|
+
For more information, please read [Work with Tokens and Organizations](https://minty.page/docs/organizations/using-tokens) on Minty Docs.
|
data/Gemfile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
gemspec
|
6
|
+
|
7
|
+
group :development do
|
8
|
+
gem 'coveralls', require: false
|
9
|
+
gem 'irb', require: false
|
10
|
+
gem 'rubocop', require: false
|
11
|
+
gem 'rubocop-rails', require: false
|
12
|
+
gem 'terminal-notifier-guard', require: false unless ENV['CIRCLECI']
|
13
|
+
end
|
14
|
+
|
15
|
+
group :test do
|
16
|
+
gem 'pp'
|
17
|
+
gem 'simplecov-cobertura'
|
18
|
+
gem 'timecop', require: false
|
19
|
+
gem 'vcr', require: false
|
20
|
+
gem 'webmock', require: false
|
21
|
+
end
|