authress-sdk 0.1.18.0 → 0.1.19.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 +4 -4
- metadata +104 -99
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7181eae557d3464a2626ffa2f35cab55a291392c7e51cb56aeb094f15127b3f2
|
4
|
+
data.tar.gz: ce4d5eab18ff90687aa34c302408c5de5dad85e97bec8e71f44d8b73c7fb57b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9de5a2e1dc97a754abfd180f517b8d17d7151ce84d8a87f009ba1e0c6291ddba53a9fc6b505576a386f48c2c9e6deee22df9e88d9fab4b3ba5f2d49162be5c1a
|
7
|
+
data.tar.gz: 6551410fd9d0c61e2049bb00a0f48fd960acadecdabd5a4a7434d28afbfa8f6e94a62f4d754f742d66cc7c8c1f20d374e5bbae15c2bc63e91b7ccfb5b488f384
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: authress-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.19.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rhosys
|
@@ -71,129 +71,133 @@ dependencies:
|
|
71
71
|
- - ">="
|
72
72
|
- !ruby/object:Gem::Version
|
73
73
|
version: 3.6.0
|
74
|
-
description:
|
75
|
-
# authress-sdk.rb
|
76
|
-
|
77
|
-
|
78
|
-
[](http://badge.fury.io/rb/authress-sdk)
|
74
|
+
description: |+
|
75
|
+
# authress-sdk.rb This is the Authress SDK used to integrate with the
|
76
|
+
authorization as a service provider Authress at https://authress.io.
|
79
77
|
|
78
|
+
[](http://badge.fury.io/rb/a
|
80
|
+
uthress-sdk)
|
80
81
|
|
81
82
|
## Usage
|
82
83
|
|
83
|
-
```sh
|
84
|
-
gem install authress-sdk
|
85
|
-
```
|
84
|
+
```sh gem install authress-sdk ```
|
86
85
|
|
87
|
-
Then required the package:
|
88
|
-
```rb
|
89
|
-
require 'authress-sdk';
|
90
|
-
```
|
86
|
+
Then required the package: ```rb require 'authress-sdk'; ```
|
91
87
|
|
92
88
|
## Getting started examples
|
93
89
|
|
94
|
-
### Authorize using a user token
|
95
|
-
```rb
|
96
|
-
require 'authress-sdk';
|
90
|
+
### Authorize using a user token ```rb require 'authress-sdk';
|
97
91
|
|
98
|
-
# create an instance of the API class during service initialization
|
99
|
-
|
100
|
-
|
92
|
+
# create an instance of the API class during service initialization # Replace
|
93
|
+
DOMAIN with the Authress domain for your account AuthressClient.configure do
|
94
|
+
|config|
|
101
95
|
config.base_url = 'https://DOMAIN.api-REGION.authress.io'
|
96
|
+
|
102
97
|
end
|
103
98
|
|
104
99
|
# on api route
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
100
|
+
route('/resources/<resourceId>'):
|
101
|
+
function getResource(resourceId) {
|
102
|
+
# Get the user token and pass it to authress
|
103
|
+
authorizationToken = request.headers.get('authorization');
|
104
|
+
AuthressClient.setToken(authorizationToken);
|
110
105
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
106
|
+
# Check Authress to authorize the user
|
107
|
+
user_id = 'user_id_example' # String | The user to check permissions on
|
108
|
+
resource_uri = `resources/${resourceId}` # String | The uri path of a resource to validate, must be URL encoded, uri segments are allowed, the resource must be a full path, and permissions are not inherited by sub-resources.
|
109
|
+
permission = 'READ' # String | Permission to check, '*' and scoped permissions can also be checked here.
|
110
|
+
begin
|
111
|
+
#Check to see if a user has permissions to a resource.
|
112
|
+
api_instance = SwaggerClient::UserPermissionsApi.new
|
113
|
+
api_instance.authorize_user(user_id, resource_uri, permission)
|
114
|
+
rescue SwaggerClient::ApiError => e
|
115
|
+
# Will throw except if the user is not authorized to read the resource
|
116
|
+
if (e.status === 404) {
|
117
|
+
return { statusCode: 404 };
|
118
|
+
}
|
119
|
+
puts "Exception when calling UserPermissionsApi->authorize_user: #{e}"
|
120
|
+
throw e;
|
121
|
+
end
|
127
122
|
|
128
|
-
|
129
|
-
|
130
|
-
```
|
123
|
+
# On success, continue with the route code to load resource and return it
|
124
|
+
return { resource: {}, statusCode: 200 };
|
131
125
|
|
132
|
-
|
133
|
-
```rb
|
134
|
-
require 'authress-sdk';
|
126
|
+
```
|
135
127
|
|
136
|
-
|
137
|
-
# Replace DOMAIN with the Authress domain for your account
|
128
|
+
### Authorize with a service client ```rb require 'authress-sdk';
|
138
129
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
130
|
+
# create an instance of the API class during service initialization #
|
131
|
+
Replace DOMAIN with the Authress domain for your account
|
132
|
+
|
133
|
+
# Create a service client in the Authress management portal and past the
|
134
|
+
access token here # This will generate a token automatically instead of
|
135
|
+
passing the user token to the api AuthressClient.configure do |config|
|
136
|
+
config.base_url = 'https://DOMAIN.api-REGION.authress.io'
|
137
|
+
accessToken = 'eyJrZXlJ....';
|
138
|
+
config.token_provider = ServiceClientTokenProvider.new(accessToken)
|
146
139
|
|
147
|
-
# on api route
|
148
|
-
[route('/resources/<resourceId>')]
|
149
|
-
function getResource(resourceId) {
|
150
|
-
# Check Authress to authorize the user
|
151
|
-
user_id = 'user_id_example' # String | The user to check permissions on
|
152
|
-
resource_uri = `resources/${resourceId}` # String | The uri path of a resource to validate, must be URL encoded, uri segments are allowed, the resource must be a full path, and permissions are not inherited by sub-resources.
|
153
|
-
permission = 'READ' # String | Permission to check, '*' and scoped permissions can also be checked here.
|
154
|
-
begin
|
155
|
-
#Check to see if a user has permissions to a resource.
|
156
|
-
api_instance = SwaggerClient::UserPermissionsApi.new
|
157
|
-
api_instance.authorize_user(user_id, resource_uri, permission)
|
158
|
-
rescue SwaggerClient::ApiError => e
|
159
|
-
# Will throw except if the user is not authorized to read the resource
|
160
|
-
if (e.status === 404) {
|
161
|
-
return { statusCode: 404 };
|
162
|
-
}
|
163
|
-
puts "Exception when calling UserPermissionsApi->authorize_user: #{e}"
|
164
|
-
throw e;
|
165
140
|
end
|
166
141
|
|
167
|
-
#
|
168
|
-
|
169
|
-
|
142
|
+
# on api route
|
143
|
+
route('/resources/<resourceId>'):
|
144
|
+
function getResource(resourceId) {
|
145
|
+
# Check Authress to authorize the user
|
146
|
+
user_id = 'user_id_example' # String | The user to check permissions on
|
147
|
+
resource_uri = `resources/${resourceId}` # String | The uri path of a resource to validate, must be URL encoded, uri segments are allowed, the resource must be a full path, and permissions are not inherited by sub-resources.
|
148
|
+
permission = 'READ' # String | Permission to check, '*' and scoped permissions can also be checked here.
|
149
|
+
begin
|
150
|
+
#Check to see if a user has permissions to a resource.
|
151
|
+
api_instance = SwaggerClient::UserPermissionsApi.new
|
152
|
+
api_instance.authorize_user(user_id, resource_uri, permission)
|
153
|
+
rescue SwaggerClient::ApiError => e
|
154
|
+
# Will throw except if the user is not authorized to read the resource
|
155
|
+
if (e.status === 404) {
|
156
|
+
return { statusCode: 404 };
|
157
|
+
}
|
158
|
+
puts "Exception when calling UserPermissionsApi->authorize_user: #{e}"
|
159
|
+
throw e;
|
160
|
+
end
|
170
161
|
|
171
|
-
|
172
|
-
|
162
|
+
# On success, continue with the route code to load resource and return it
|
163
|
+
return { resource: {}, statusCode: 200 };
|
173
164
|
|
174
|
-
|
165
|
+
```
|
166
|
+
|
167
|
+
### Creating resources When a user creates a resource in your application,
|
168
|
+
we want to ensure that they get access own that resource.
|
169
|
+
|
170
|
+
You may receive **User does not have sufficient access to grant
|
171
|
+
permissions to resources** as an error along with the status code
|
172
|
+
*<b>403</b>*. This means that the service client or user jwt does not have
|
173
|
+
access to create the access record. If using a service client, go to the
|
174
|
+
Authress portal and create a one time record which grants the service
|
175
|
+
client `Authress:Owner` to `Resources/` so that it can manage access
|
176
|
+
records for these types of resources.
|
177
|
+
|
178
|
+
```rb require 'authress-sdk';
|
179
|
+
|
180
|
+
begin
|
181
|
+
#Create a new access record.
|
182
|
+
new_record = SwaggerClient::Body3.new {
|
183
|
+
name: `Access To New Resource ${NewResourceId}`,
|
184
|
+
users: [{ userId: requestUserId }],
|
185
|
+
statements: [{
|
186
|
+
resources: [{ resourceUri: `Resources/${NewResourceId}` }],
|
187
|
+
# Owner by default gives full control over this new resource, including the ability to grant others access as well.
|
188
|
+
roles: ['Authress:Owner']
|
189
|
+
}]
|
190
|
+
};
|
191
|
+
api_instance = SwaggerClient::AccessRecordsApi.new
|
192
|
+
result = api_instance.create_record(new_record)
|
193
|
+
puts result
|
194
|
+
|
195
|
+
rescue SwaggerClient::ApiError => e
|
196
|
+
puts "Exception when calling AccessRecordsApi->create_record: #{e}"
|
197
|
+
|
198
|
+
end ```
|
175
199
|
|
176
|
-
```rb
|
177
|
-
require 'authress-sdk';
|
178
200
|
|
179
|
-
begin
|
180
|
-
#Create a new access record.
|
181
|
-
new_record = SwaggerClient::Body3.new {
|
182
|
-
name: `Access To New Resource ${NewResourceId}`,
|
183
|
-
users: [{ userId: requestUserId }],
|
184
|
-
statements: [{
|
185
|
-
resources: [{ resourceUri: `Resources/${NewResourceId}` }],
|
186
|
-
# Owner by default gives full control over this new resource, including the ability to grant others access as well.
|
187
|
-
roles: ['Authress:Owner']
|
188
|
-
}]
|
189
|
-
};
|
190
|
-
api_instance = SwaggerClient::AccessRecordsApi.new
|
191
|
-
result = api_instance.create_record(new_record)
|
192
|
-
puts result
|
193
|
-
rescue SwaggerClient::ApiError => e
|
194
|
-
puts "Exception when calling AccessRecordsApi->create_record: #{e}"
|
195
|
-
end
|
196
|
-
```
|
197
201
|
email:
|
198
202
|
- support@authress.io
|
199
203
|
executables: []
|
@@ -311,3 +315,4 @@ specification_version: 4
|
|
311
315
|
summary: The Authress SDK for Ruby provides authorization as a service with fully
|
312
316
|
compatible REST apis to integrate with Authress at https://authress.io.
|
313
317
|
test_files: []
|
318
|
+
...
|