diff --git a/Gemfile.lock b/Gemfile.lock index 87cbc611..91aeb76c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - workos (0.1.0) + workos (0.1.1) sorbet-runtime (~> 0.5) GEM @@ -56,7 +56,7 @@ GEM simplecov-html (0.10.2) sorbet (0.5.5181) sorbet-static (= 0.5.5181) - sorbet-runtime (0.5.5182) + sorbet-runtime (0.5.5373) sorbet-static (0.5.5181-universal-darwin-14) unicode-display_width (1.6.0) url (0.3.2) diff --git a/docs/WorkOS.html b/docs/WorkOS.html index c9b9a2a5..770d7e2a 100644 --- a/docs/WorkOS.html +++ b/docs/WorkOS.html @@ -88,7 +88,7 @@

Overview

-

typed: strict

+

Use the WorkOS module to authenticate your requests to the WorkOS API. The gem will read your API key automatically from the ENV var `WORKOS_KEY`. Alternatively, you can set the key yourself with `WorkOS.key = [your api key]` somewhere in the load path of your application, such as an initializer.

@@ -120,12 +120,12 @@

API_HOSTNAME =
-
'api.workos.com'
+
ENV['WORKOS_API_HOSTNAME'] || 'api.workos.com'
VERSION =
-
'0.1.0'
+
'0.1.1'
@@ -314,7 +314,7 @@

diff --git a/docs/WorkOS/APIError.html b/docs/WorkOS/APIError.html index a866910f..4172506b 100644 --- a/docs/WorkOS/APIError.html +++ b/docs/WorkOS/APIError.html @@ -150,7 +150,7 @@

Constructor Details

diff --git a/docs/WorkOS/AuditLog.html b/docs/WorkOS/AuditLog.html index baf4a8a5..5aac8123 100644 --- a/docs/WorkOS/AuditLog.html +++ b/docs/WorkOS/AuditLog.html @@ -225,7 +225,7 @@

diff --git a/docs/WorkOS/AuthenticationError.html b/docs/WorkOS/AuthenticationError.html index 8df1dcb5..9f85e195 100644 --- a/docs/WorkOS/AuthenticationError.html +++ b/docs/WorkOS/AuthenticationError.html @@ -150,7 +150,7 @@

Constructor Details

diff --git a/docs/WorkOS/Base.html b/docs/WorkOS/Base.html index 2480b7a1..092a92f5 100644 --- a/docs/WorkOS/Base.html +++ b/docs/WorkOS/Base.html @@ -93,7 +93,18 @@ +

Overview

+
+ +

The Base class handles setting and reading the WorkOS API Key for authentication

+ +
+
+
+ + +
@@ -197,12 +208,12 @@

 
 
-13
-14
-15
+15 +16 +17 -
# File 'lib/workos/base.rb', line 13
+      
# File 'lib/workos/base.rb', line 15
 
 def key
   @key
@@ -245,12 +256,12 @@ 

 
 
-7
-8
-9
+9 +10 +11

-
# File 'lib/workos/base.rb', line 7
+      
# File 'lib/workos/base.rb', line 9
 
 def key
   @key
@@ -266,7 +277,7 @@ 

diff --git a/docs/WorkOS/Client.html b/docs/WorkOS/Client.html index 4fd3b37f..e3c21979 100644 --- a/docs/WorkOS/Client.html +++ b/docs/WorkOS/Client.html @@ -98,7 +98,18 @@ +

Overview

+
+ +

A Net::HTTP based API client for interacting with the WorkOS API

+ +
+
+
+ + +
@@ -249,17 +260,17 @@

 
 
-11
 12
 13
 14
 15
 16
 17
-18
+18 +19

-
# File 'lib/workos/client.rb', line 11
+      
# File 'lib/workos/client.rb', line 12
 
 def client
   return @client if defined?(@client)
@@ -289,17 +300,17 @@ 

 
 
-21
 22
 23
 24
 25
 26
 27
-28
+28 +29

-
# File 'lib/workos/client.rb', line 21
+      
# File 'lib/workos/client.rb', line 22
 
 def execute_request(request:)
   response = client.request(request)
@@ -329,7 +340,6 @@ 

 
 
-53
 54
 55
 56
@@ -358,10 +368,11 @@ 

79 80 81 -82

+82 +83

-
# File 'lib/workos/client.rb', line 53
+      
# File 'lib/workos/client.rb', line 54
 
 def handle_error_response(response:)
   http_status = response.code.to_i
@@ -413,15 +424,15 @@ 

 
 
-31
 32
 33
 34
 35
-36
+36 +37

-
# File 'lib/workos/client.rb', line 31
+      
# File 'lib/workos/client.rb', line 32
 
 def post_request(path:, body: nil)
   request = Net::HTTP::Post.new(path, 'Content-Type' => 'application/json')
@@ -449,7 +460,6 @@ 

 
 
-39
 40
 41
 42
@@ -458,10 +468,11 @@ 

45 46 47 -48

+48 +49

-
# File 'lib/workos/client.rb', line 39
+      
# File 'lib/workos/client.rb', line 40
 
 def user_agent
   engine = defined?(::RUBY_ENGINE) ? ::RUBY_ENGINE : 'Ruby'
@@ -483,7 +494,7 @@ 

diff --git a/docs/WorkOS/InvalidRequestError.html b/docs/WorkOS/InvalidRequestError.html index 3fd90e5d..cbc530f6 100644 --- a/docs/WorkOS/InvalidRequestError.html +++ b/docs/WorkOS/InvalidRequestError.html @@ -150,7 +150,7 @@

Constructor Details

diff --git a/docs/WorkOS/Profile.html b/docs/WorkOS/Profile.html index 7598f0ff..6d4dfeeb 100644 --- a/docs/WorkOS/Profile.html +++ b/docs/WorkOS/Profile.html @@ -778,7 +778,7 @@

diff --git a/docs/WorkOS/SSO.html b/docs/WorkOS/SSO.html index f2d7d2c2..621f461a 100644 --- a/docs/WorkOS/SSO.html +++ b/docs/WorkOS/SSO.html @@ -187,6 +187,30 @@

Fetch the profile details for the authenticated SSO user.

+ + + +
  • + + + .promote_draft_connection(token:) ⇒ Bool + + + + + + + + + + + + + +
    +

    Promote a DraftConnection created via IdP Link Embed such that the Enterprise users can begin signing into your application.

    +
    +
  • @@ -538,6 +562,118 @@

    + + +
    +

    + + .promote_draft_connection(token:) ⇒ Bool + + + + + +

    +
    + +

    Promote a DraftConnection created via IdP Link Embed such that the Enterprise users can begin signing into your application.

    + +

    you by the IdP Link Embed

    + + +
    +
    +
    + +
    +

    Examples:

    + + +
    WorkOS::SSO.promote_draft_connection(
    +  token: 'draft_conn_429u59js',
    +)
    +=> true
    + +
    +

    Parameters:

    +
      + +
    • + + token + + + (String) + + + + — +
      +

      The draft connection token that's been provided to

      +
      + +
    • + +
    + +

    Returns:

    +
      + +
    • + + + (Bool) + + + + — +
      • +

        returns `true` if successful, `false` otherwise.

        +
      +
      + +
    • + +
    + +

    See Also:

    + + +
    + + + + +
    +
    +
    +
    +142
    +143
    +144
    +145
    +146
    +147
    +148
    +149
    +150
    +
    +
    # File 'lib/workos/sso.rb', line 142
    +
    +def promote_draft_connection(token:)
    +  request = bearer_post_request(
    +    path: "/draft_connections/#{token}/activate",
    +  )
    +
    +  response = client.request(request)
    +
    +  response.is_a? Net::HTTPSuccess
    +end
    +
    @@ -545,7 +681,7 @@

    diff --git a/docs/WorkOS/Types.html b/docs/WorkOS/Types.html index ba5c7c91..8a461d9b 100644 --- a/docs/WorkOS/Types.html +++ b/docs/WorkOS/Types.html @@ -118,7 +118,7 @@

    Overview

    diff --git a/docs/WorkOS/Types/ProfileStruct.html b/docs/WorkOS/Types/ProfileStruct.html index 8346b608..9189c531 100644 --- a/docs/WorkOS/Types/ProfileStruct.html +++ b/docs/WorkOS/Types/ProfileStruct.html @@ -125,7 +125,7 @@

    Overview

    diff --git a/docs/WorkOS/Types/Provider.html b/docs/WorkOS/Types/Provider.html index f03e7851..9d8d21e2 100644 --- a/docs/WorkOS/Types/Provider.html +++ b/docs/WorkOS/Types/Provider.html @@ -125,7 +125,7 @@

    Overview

    diff --git a/docs/WorkOS/WorkOSError.html b/docs/WorkOS/WorkOSError.html index e3fc510d..a6a51246 100644 --- a/docs/WorkOS/WorkOSError.html +++ b/docs/WorkOS/WorkOSError.html @@ -109,7 +109,7 @@

    Overview

    -

    rubocop:disable Style/Documentation

    +

    Parent class for WorkOS related errors

    @@ -281,14 +281,14 @@

     
     
    -19
     20
     21
     22
    -23
    +23 +24

    -
    # File 'lib/workos/errors.rb', line 19
    +      
    # File 'lib/workos/errors.rb', line 20
     
     def initialize(message: nil, http_status: nil, request_id: nil)
       @message = message
    @@ -333,12 +333,12 @@ 

     
     
    -9
     10
    -11
    +11 +12

    -
    # File 'lib/workos/errors.rb', line 9
    +      
    # File 'lib/workos/errors.rb', line 10
     
     def http_status
       @http_status
    @@ -376,12 +376,12 @@ 

     
     
    -10
     11
    -12
    +12 +13

    -
    # File 'lib/workos/errors.rb', line 10
    +      
    # File 'lib/workos/errors.rb', line 11
     
     def request_id
       @request_id
    @@ -413,14 +413,14 @@ 

     
     
    -26
     27
     28
     29
    -30
    +30 +31

    -
    # File 'lib/workos/errors.rb', line 26
    +      
    # File 'lib/workos/errors.rb', line 27
     
     def to_s
       status_string = @http_status.nil? ? '' : "Status #{@http_status}, "
    @@ -437,7 +437,7 @@ 

    diff --git a/docs/file.README.html b/docs/file.README.html index 590359ad..93586f6d 100644 --- a/docs/file.README.html +++ b/docs/file.README.html @@ -242,7 +242,7 @@

    The SSO Module

    diff --git a/docs/index.html b/docs/index.html index 81fef4f4..bbea5bb5 100644 --- a/docs/index.html +++ b/docs/index.html @@ -240,7 +240,7 @@

    Namespace Listing A-Z

    diff --git a/docs/method_list.html b/docs/method_list.html index 285326d5..f05ad726 100644 --- a/docs/method_list.html +++ b/docs/method_list.html @@ -166,7 +166,7 @@

    Method List

  • - #key + key WorkOS::Base
  • @@ -174,7 +174,7 @@

    Method List

  • - key + #key WorkOS::Base
  • @@ -221,6 +221,14 @@

    Method List

  • +
    + promote_draft_connection + WorkOS::SSO +
    +
  • + + +
  • #request_id WorkOS::WorkOSError @@ -228,7 +236,7 @@

    Method List

  • -
  • +
  • #to_json WorkOS::Profile @@ -236,7 +244,7 @@

    Method List

  • -
  • +
  • #to_s WorkOS::WorkOSError @@ -244,7 +252,7 @@

    Method List

  • -
  • +
  • #user_agent WorkOS::Client diff --git a/docs/top-level-namespace.html b/docs/top-level-namespace.html index b5e35f91..08152ec3 100644 --- a/docs/top-level-namespace.html +++ b/docs/top-level-namespace.html @@ -100,7 +100,7 @@

    Defined Under Namespace

    diff --git a/lib/workos.rb b/lib/workos.rb index 21a8a644..f5ed8f4f 100644 --- a/lib/workos.rb +++ b/lib/workos.rb @@ -11,7 +11,7 @@ # `WorkOS.key = [your api key]` somewhere in the load path of # your application, such as an initializer. module WorkOS - API_HOSTNAME = 'api.workos.com' + API_HOSTNAME = ENV['WORKOS_API_HOSTNAME'] || 'api.workos.com' def self.key=(value) Base.key = value diff --git a/lib/workos/base.rb b/lib/workos/base.rb index 0d484469..9e3611de 100644 --- a/lib/workos/base.rb +++ b/lib/workos/base.rb @@ -1,8 +1,10 @@ # frozen_string_literal: true # typed: true -# rubocop:disable Style/Documentation + module WorkOS + ## The Base class handles setting and reading the WorkOS + ## API Key for authentication module Base attr_accessor :key @@ -14,4 +16,3 @@ class << self end end end -# rubocop:enable Style/Documentation diff --git a/lib/workos/client.rb b/lib/workos/client.rb index ca0d85ed..723e5e9a 100644 --- a/lib/workos/client.rb +++ b/lib/workos/client.rb @@ -1,8 +1,9 @@ # frozen_string_literal: true # typed: true -# rubocop:disable Style/Documentation + module WorkOS + # A Net::HTTP based API client for interacting with the WorkOS API module Client extend T::Sig include Kernel @@ -83,4 +84,3 @@ def handle_error_response(response:) # rubocop:enable Metrics/MethodLength, Metrics/AbcSize end end -# rubocop:enable Style/Documentation diff --git a/lib/workos/errors.rb b/lib/workos/errors.rb index 5c4e8c4c..c02544bf 100644 --- a/lib/workos/errors.rb +++ b/lib/workos/errors.rb @@ -1,8 +1,9 @@ # frozen_string_literal: true # typed: true + module WorkOS - # rubocop:disable Style/Documentation + # Parent class for WorkOS related errors class WorkOSError < StandardError extend T::Sig @@ -43,6 +44,4 @@ class AuthenticationError < WorkOSError; end # InvalidRequestError is raised when a request is initiated with invalid # parameters. class InvalidRequestError < WorkOSError; end - - # rubocop:enable Style/Documentation end diff --git a/lib/workos/sso.rb b/lib/workos/sso.rb index b18fc874..17d497f1 100644 --- a/lib/workos/sso.rb +++ b/lib/workos/sso.rb @@ -119,6 +119,36 @@ def profile(code:, project_id:) WorkOS::Profile.new(response.body) end + sig do + params( + token: String, + ).returns(T::Boolean) + end + + # Promote a DraftConnection created via IdP Link Embed such that the + # Enterprise users can begin signing into your application. + # + # @param [String] token The draft connection token that's been provided to + # you by the IdP Link Embed + # + # @example + # WorkOS::SSO.promote_draft_connection( + # token: 'draft_conn_429u59js', + # ) + # => true + # + # @return [Bool] - returns `true` if successful, `false` otherwise. + # @see https://github.com/workos-inc/ruby-idp-link-example + def promote_draft_connection(token:) + request = bearer_post_request( + path: "/draft_connections/#{token}/activate", + ) + + response = client.request(request) + + response.is_a? Net::HTTPSuccess + end + private sig do @@ -158,6 +188,12 @@ def check_and_raise_profile_error(response:) ) end # rubocop:enable Metrics/MethodLength + + def bearer_post_request(path:, body: nil) + request = post_request(path: path, body: body) + request['Authorization'] = "Bearer #{WorkOS.key!}" + request + end end end end diff --git a/lib/workos/types.rb b/lib/workos/types.rb index 085f861b..bdc734d6 100644 --- a/lib/workos/types.rb +++ b/lib/workos/types.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -# typed: strong +# typed: strict module WorkOS diff --git a/lib/workos/types/provider_enum.rb b/lib/workos/types/provider_enum.rb index 369326b9..71d99078 100644 --- a/lib/workos/types/provider_enum.rb +++ b/lib/workos/types/provider_enum.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true # typed: strict + module WorkOS module Types # The ProviderEnum is type-safe declarations of a diff --git a/lib/workos/version.rb b/lib/workos/version.rb index 27e1014f..e9b42932 100644 --- a/lib/workos/version.rb +++ b/lib/workos/version.rb @@ -3,5 +3,5 @@ module WorkOS - VERSION = '0.1.0' + VERSION = '0.1.1' end diff --git a/spec/lib/workos/sso_spec.rb b/spec/lib/workos/sso_spec.rb index ca73ce49..beb15ce0 100644 --- a/spec/lib/workos/sso_spec.rb +++ b/spec/lib/workos/sso_spec.rb @@ -210,4 +210,41 @@ end end end + + describe '.promote_draft_connection' do + let(:token) { 'draft_conn_id' } + let(:project_id) { 'proj_0239u590h' } + + context 'with a valid request' do + before do + stub_request( + :post, + "https://api.workos.com/draft_connections/#{token}/activate", + ).to_return(status: 200) + end + it 'returns true' do + response = described_class.promote_draft_connection( + token: token, + ) + + expect(response).to be(true) + end + end + + context 'with an invalid request' do + before do + stub_request( + :post, + "https://api.workos.com/draft_connections/#{token}/activate", + ).to_return(status: 403) + end + it 'returns true' do + response = described_class.promote_draft_connection( + token: token, + ) + + expect(response).to be(false) + end + end + end end