Skip to content

Commit

Permalink
Release 1.0 version
Browse files Browse the repository at this point in the history
  • Loading branch information
wparad committed Dec 20, 2020
1 parent 113d62c commit 4126f92
Show file tree
Hide file tree
Showing 260 changed files with 1,419 additions and 2,924 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ jobs:
run: gem install bundler:'~> 2.2.2' && bundle install

- name: Run build
run: bundle exec rake --trace
run: |
bundle exec rake --trace
bundle exec rake build --trace
- name: Deploy to RubyGems
if: github.ref != 'refs/heads/main' && github.event_name == 'push'
run: |
bundle exec rake build --trace
bundle exec rake publish_git_tag --trace
gem push pkg/*.gem -V
env:
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Generated by: https://github.com/swagger-api/swagger-codegen.git
#

*.gem
*.rbc
Expand Down
68 changes: 36 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,86 +12,86 @@ gem install authress-sdk

Then required the package:
```rb
require 'authress-sdk';
require 'authress-sdk'
```

## Getting started examples

### Authorize using a user token
```rb
require 'authress-sdk';
require 'authress-sdk'

# create an instance of the API class during service initialization
# Replace DOMAIN with the Authress domain for your account
AuthressClient.configure do |config|
AuthressSdk.configure do |config|
config.base_url = 'https://DOMAIN.api-REGION.authress.io'
end

# on api route
[route('/resources/<resourceId>')]
function getResource(resourceId) {
def getResource(resourceId)
# Get the user token and pass it to authress
authorizationToken = request.headers.get('authorization');
AuthressClient.setToken(authorizationToken);
authorizationToken = request.headers.get('authorization')
AuthressSdk::AuthressClient.set_token(authorizationToken)

# Check Authress to authorize the user
user_id = 'user_id_example' # String | The user to check permissions on
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.
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.
permission = 'READ' # String | Permission to check, '*' and scoped permissions can also be checked here.
begin
#Check to see if a user has permissions to a resource.
api_instance = SwaggerClient::UserPermissionsApi.new
api_instance = AuthressSdk::UserPermissionsApi.new
api_instance.authorize_user(user_id, resource_uri, permission)
rescue SwaggerClient::ApiError => e
rescue AuthressSdk::ApiError => e
# Will throw except if the user is not authorized to read the resource
if (e.status === 404) {
return { statusCode: 404 };
return { statusCode: 404 }
}
puts "Exception when calling UserPermissionsApi->authorize_user: #{e}"
throw e;
raise
end

# On success, continue with the route code to load resource and return it
return { resource: {}, statusCode: 200 };
return { resource: {}, statusCode: 200 }
```

### Authorize with a service client
```rb
require 'authress-sdk';
require 'authress-sdk'

# create an instance of the API class during service initialization
# Replace DOMAIN with the Authress domain for your account

# Create a service client in the Authress management portal and past the access token here
# This will generate a token automatically instead of passing the user token to the api
AuthressClient.configure do |config|
AuthressSdk.configure do |config|
config.base_url = 'https://DOMAIN.api-REGION.authress.io'
accessToken = 'eyJrZXlJ....';
config.token_provider = ServiceClientTokenProvider.new(accessToken)
client_access_key = 'eyJrZXlJ....'
config.token_provider = AuthressSdk::ServiceClientTokenProvider.new(client_access_key)
end

# on api route
[route('/resources/<resourceId>')]
function getResource(resourceId) {
def getResource(resourceId) {
# Check Authress to authorize the user
user_id = 'user_id_example' # String | The user to check permissions on
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.
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.
permission = 'READ' # String | Permission to check, '*' and scoped permissions can also be checked here.
begin
#Check to see if a user has permissions to a resource.
api_instance = SwaggerClient::UserPermissionsApi.new
api_instance = AuthressSdk::UserPermissionsApi.new
api_instance.authorize_user(user_id, resource_uri, permission)
rescue SwaggerClient::ApiError => e
# Will throw except if the user is not authorized to read the resource
rescue AuthressSdk::ApiError => e
# Will raise exception if the user is not authorized to read the resource
if (e.status === 404) {
return { statusCode: 404 };
return { statusCode: 404 }
}
puts "Exception when calling UserPermissionsApi->authorize_user: #{e}"
throw e;
raise
end

# On success, continue with the route code to load resource and return it
return { resource: {}, statusCode: 200 };
return { resource: {}, statusCode: 200 }
```

### Creating resources
Expand All @@ -100,23 +100,27 @@ When a user creates a resource in your application, we want to ensure that they
You may receive **User does not have sufficient access to grant permissions to resources** as an error along with the status code **403**. This means that the service client or user jwt does not have access to create the access record. If using a service client, go to the Authress portal and create a one time record which grants the service client `Authress:Owner` to `Resources/` so that it can manage access records for these types of resources.

```rb
require 'authress-sdk';
require 'authress-sdk'

begin
#Create a new access record.
new_record = SwaggerClient::Body3.new {
name: `Access To New Resource ${NewResourceId}`,
new_record = AuthressSdk::Body3.new {
name: "Access To New Resource #{NewResourceId}",
users: [{ userId: requestUserId }],
statements: [{
resources: [{ resourceUri: `Resources/${NewResourceId}` }],
resources: [{ resourceUri: "Resources/#{NewResourceId}" }],
# Owner by default gives full control over this new resource, including the ability to grant others access as well.
roles: ['Authress:Owner']
}]
};
api_instance = SwaggerClient::AccessRecordsApi.new
}
api_instance = AuthressSdk::AccessRecordsApi.new
result = api_instance.create_record(new_record)
puts result
rescue SwaggerClient::ApiError => e
rescue AuthressSdk::ApiError => e
puts "Exception when calling AccessRecordsApi->create_record: #{e}"
raise
end
```
```

### Early release
* Add in access_token handling to client
2 changes: 1 addition & 1 deletion docs/AccessRecord.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SwaggerClient::AccessRecord
# AuthressSdk::AccessRecord

## Properties
Name | Type | Description | Notes
Expand Down
2 changes: 1 addition & 1 deletion docs/AccessRecordCollection.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SwaggerClient::AccessRecordCollection
# AuthressSdk::AccessRecordCollection

## Properties
Name | Type | Description | Notes
Expand Down
2 changes: 1 addition & 1 deletion docs/AccessRecordCollectionRecords.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SwaggerClient::AccessRecordCollectionRecords
# AuthressSdk::AccessRecordCollectionRecords

## Properties
Name | Type | Description | Notes
Expand Down
Loading

0 comments on commit 4126f92

Please sign in to comment.