# The MIT License (MIT) # # Copyright (c) 2023 Losant IoT, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. require "json" module PlatformRest # Class containing all the actions for the Auth Resource class Auth def initialize(client) @client = client end # Authenticates a device using the provided credentials. # # Authentication: # No api access token is required to call this action. # # Parameters: # * {hash} credentials - Device authentication credentials (https://api.losant.com/#/definitions/deviceCredentials) # * {string} losantdomain - Domain scope of request (rarely needed) # * {boolean} _actions - Return resource actions in response # * {boolean} _links - Return resource link in response # * {boolean} _embedded - Return embedded resources in response # # Responses: # * 200 - Successful authentication. The included api access token by default has the scope 'all.Device'. (https://api.losant.com/#/definitions/authedDevice) # # Errors: # * 400 - Error if malformed request (https://api.losant.com/#/definitions/error) # * 401 - Unauthorized error if authentication fails (https://api.losant.com/#/definitions/error) def authenticate_device(params = {}) params = Utils.symbolize_hash_keys(params) query_params = { _actions: false, _links: true, _embedded: true } headers = {} body = nil raise ArgumentError.new("credentials is required") unless params.has_key?(:credentials) body = params[:credentials] if params.has_key?(:credentials) headers[:losantdomain] = params[:losantdomain] if params.has_key?(:losantdomain) query_params[:_actions] = params[:_actions] if params.has_key?(:_actions) query_params[:_links] = params[:_links] if params.has_key?(:_links) query_params[:_embedded] = params[:_embedded] if params.has_key?(:_embedded) path = "/auth/device" @client.request( method: :post, path: path, query: query_params, headers: headers, body: body) end # Authenticates a user using the provided credentials. # # Authentication: # No api access token is required to call this action. # # Parameters: # * {hash} credentials - User authentication credentials (https://api.losant.com/#/definitions/userCredentials) # * {string} losantdomain - Domain scope of request (rarely needed) # * {boolean} _actions - Return resource actions in response # * {boolean} _links - Return resource link in response # * {boolean} _embedded - Return embedded resources in response # # Responses: # * 200 - Successful authentication. The included api access token has the scope 'all.User'. (https://api.losant.com/#/definitions/authedUser) # # Errors: # * 400 - Error if malformed request (https://api.losant.com/#/definitions/error) # * 401 - Unauthorized error if authentication fails (https://api.losant.com/#/definitions/error) def authenticate_user(params = {}) params = Utils.symbolize_hash_keys(params) query_params = { _actions: false, _links: true, _embedded: true } headers = {} body = nil raise ArgumentError.new("credentials is required") unless params.has_key?(:credentials) body = params[:credentials] if params.has_key?(:credentials) headers[:losantdomain] = params[:losantdomain] if params.has_key?(:losantdomain) query_params[:_actions] = params[:_actions] if params.has_key?(:_actions) query_params[:_links] = params[:_links] if params.has_key?(:_links) query_params[:_embedded] = params[:_embedded] if params.has_key?(:_embedded) path = "/auth/user" @client.request( method: :post, path: path, query: query_params, headers: headers, body: body) end # Authenticates a user via GitHub OAuth. # # Authentication: # No api access token is required to call this action. # # Parameters: # * {hash} oauth - User authentication credentials (access token) (https://api.losant.com/#/definitions/githubLogin) # * {string} losantdomain - Domain scope of request (rarely needed) # * {boolean} _actions - Return resource actions in response # * {boolean} _links - Return resource link in response # * {boolean} _embedded - Return embedded resources in response # # Responses: # * 200 - Successful authentication. The included api access token has the scope 'all.User'. (https://api.losant.com/#/definitions/authedUser) # # Errors: # * 400 - Error if malformed request (https://api.losant.com/#/definitions/error) # * 401 - Unauthorized error if authentication fails (https://api.losant.com/#/definitions/error) def authenticate_user_github(params = {}) params = Utils.symbolize_hash_keys(params) query_params = { _actions: false, _links: true, _embedded: true } headers = {} body = nil raise ArgumentError.new("oauth is required") unless params.has_key?(:oauth) body = params[:oauth] if params.has_key?(:oauth) headers[:losantdomain] = params[:losantdomain] if params.has_key?(:losantdomain) query_params[:_actions] = params[:_actions] if params.has_key?(:_actions) query_params[:_links] = params[:_links] if params.has_key?(:_links) query_params[:_embedded] = params[:_embedded] if params.has_key?(:_embedded) path = "/auth/user/github" @client.request( method: :post, path: path, query: query_params, headers: headers, body: body) end # Authenticates a user via a SAML response. # # Authentication: # No api access token is required to call this action. # # Parameters: # * {hash} saml - Encoded SAML response from an IDP for a user. (https://api.losant.com/#/definitions/samlResponse) # * {string} losantdomain - Domain scope of request (rarely needed) # * {boolean} _actions - Return resource actions in response # * {boolean} _links - Return resource link in response # * {boolean} _embedded - Return embedded resources in response # # Responses: # * 200 - Successful authentication. The included api access token has the scope 'all.User'. (https://api.losant.com/#/definitions/authedUser) # # Errors: # * 400 - Error if malformed request (https://api.losant.com/#/definitions/error) # * 401 - Unauthorized error if authentication fails (https://api.losant.com/#/definitions/error) def authenticate_user_saml(params = {}) params = Utils.symbolize_hash_keys(params) query_params = { _actions: false, _links: true, _embedded: true } headers = {} body = nil raise ArgumentError.new("saml is required") unless params.has_key?(:saml) body = params[:saml] if params.has_key?(:saml) headers[:losantdomain] = params[:losantdomain] if params.has_key?(:losantdomain) query_params[:_actions] = params[:_actions] if params.has_key?(:_actions) query_params[:_links] = params[:_links] if params.has_key?(:_links) query_params[:_embedded] = params[:_embedded] if params.has_key?(:_embedded) path = "/auth/user/saml" @client.request( method: :post, path: path, query: query_params, headers: headers, body: body) end # Checks email domain for SSO configuration. # # Authentication: # No api access token is required to call this action. # # Parameters: # * {string} email - The email address associated with the user login # * {string} losantdomain - Domain scope of request (rarely needed) # * {boolean} _actions - Return resource actions in response # * {boolean} _links - Return resource link in response # * {boolean} _embedded - Return embedded resources in response # # Responses: # * 200 - Successful finding SSO for domain. Returns SSO request URL and type. (https://api.losant.com/#/definitions/ssoRequest) # * 204 - No domain associated with an SSO configuration # # Errors: # * 400 - Error if malformed request (https://api.losant.com/#/definitions/error) def sso_domain(params = {}) params = Utils.symbolize_hash_keys(params) query_params = { _actions: false, _links: true, _embedded: true } headers = {} body = nil raise ArgumentError.new("email is required") unless params.has_key?(:email) query_params[:email] = params[:email] if params.has_key?(:email) headers[:losantdomain] = params[:losantdomain] if params.has_key?(:losantdomain) query_params[:_actions] = params[:_actions] if params.has_key?(:_actions) query_params[:_links] = params[:_links] if params.has_key?(:_links) query_params[:_embedded] = params[:_embedded] if params.has_key?(:_embedded) path = "/auth/ssoDomain" @client.request( method: :get, path: path, query: query_params, headers: headers, body: body) end end end