RubyGems Navigation menu

authress-sdk 0.1.19.0

# authress-sdk.rb This is the Authress SDK used to integrate with the authorization as a service provider Authress at https://authress.io. [![Gem Version](https://badge.fury.io/rb/authress-sdk.svg)](http://badge.fury.io/rb/a uthress-sdk) ## Usage ```sh gem install authress-sdk ``` Then required the package: ```rb require 'authress-sdk'; ``` ## Getting started examples ### Authorize using a user token ```rb 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| config.base_url = 'https://DOMAIN.api-REGION.authress.io' end # on api route route('/resources/'): function getResource(resourceId) { # Get the user token and pass it to authress authorizationToken = request.headers.get('authorization'); AuthressClient.setToken(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. 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.authorize_user(user_id, resource_uri, permission) rescue SwaggerClient::ApiError => e # Will throw except if the user is not authorized to read the resource if (e.status === 404) { return { statusCode: 404 }; } puts "Exception when calling UserPermissionsApi->authorize_user: #{e}" throw e; end # On success, continue with the route code to load resource and return it return { resource: {}, statusCode: 200 }; ``` ### Authorize with a service client ```rb 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| config.base_url = 'https://DOMAIN.api-REGION.authress.io' accessToken = 'eyJrZXlJ....'; config.token_provider = ServiceClientTokenProvider.new(accessToken) end # on api route route('/resources/'): function 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. 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.authorize_user(user_id, resource_uri, permission) rescue SwaggerClient::ApiError => e # Will throw except if the user is not authorized to read the resource if (e.status === 404) { return { statusCode: 404 }; } puts "Exception when calling UserPermissionsApi->authorize_user: #{e}" throw e; end # On success, continue with the route code to load resource and return it return { resource: {}, statusCode: 200 }; ``` ### Creating resources When a user creates a resource in your application, we want to ensure that they get access own that resource. You may receive **User does not have sufficient access to grant permissions to resources** as an error along with the status code *<b>403</b>*. 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'; begin #Create a new access record. new_record = SwaggerClient::Body3.new { name: `Access To New Resource ${NewResourceId}`, users: [{ userId: requestUserId }], statements: [{ 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 result = api_instance.create_record(new_record) puts result rescue SwaggerClient::ApiError => e puts "Exception when calling AccessRecordsApi->create_record: #{e}" end ```

Gemfile:
=

Installeer:
=

Versies:

  1. 2.0.47.0 October 29, 2024 (35 KB)
  2. 2.0.45.0 May 01, 2024 (34,5 KB)
  3. 2.0.43.0 May 01, 2024 (34,5 KB)
  4. 2.0.41.0 February 21, 2024 (33 KB)
  5. 2.0.40.0 August 24, 2023 (33 KB)
  6. 0.1.19.0 December 20, 2020 (44,5 KB)
Toon alle versies (15 totaal)

Runtime afhankelijkheden (2):

json ~> 2.1, >= 2.1.0
typhoeus ~> 1.0, >= 1.0.1

Development afhankelijkheden (1):

rspec ~> 3.6, >= 3.6.0

Eigenaren:

Pushed by:

Authors:

  • Rhosys, Authress

SHA 256 checksum:

=

Total downloads 9.895

Voor deze versie 1.426

Versie vrijgegeven:

Licentie:

Apache-2.0

Required Ruby Version: >= 2.0

Links: