Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce new SSO module and tests structure #39

Merged
merged 42 commits into from
Nov 10, 2023

Conversation

LauraBeatris
Copy link
Contributor

@LauraBeatris LauraBeatris commented Oct 28, 2023

Bug fixes

  • Fixed the extension of config modules to be exs. Those weren't loading due to being defined as ex.

Summary

  • Introduce type specifications to all functions from SSO module. This helps the developers to quickly know what to pass to a function and what to expect to return.
  • Restructure module architecture with response structs.
  • Use new WorkOS.Client and remove the deprecated WorkOS.API from SSO module.
  • Update mix.ex with the modules group. This will be helpful when looking at ExDocs.
  • Refactor tests, to have a better Tesla mocking strategy, and assert against status, body, and params.

Usage

{:ok, authorization_url} =
  WorkOS.SSO.get_authorization_url(%{
    provider: "GoogleOAuth",
    redirect_uri: "redirect-uri.com",
    client_id: "client-id"
  })

{:ok, %WorkOS.SSO.ProfileAndToken{access_token: access_token, profile: profile}} =
  WorkOS.SSO.get_profile_and_token(client, %{
    code: "code-123"
  })

{:ok, %WorkOS.SSO.Profile{id: id}} =
  WorkOS.SSO.get_profile(client, %{
    access_token:  "access_token"
 })

{:ok, %WorkOS.SSO.Connection{id: id}} =
  WorkOS.SSO.get_connection(client, "connection-id")

{:ok, %WorkOS.List{}} =
  WorkOS.SSO.list_connections(client, %{})

{:ok, %WorkOS.Empty{}} = WorkOS.SSO.delete_connection(client, "connection-id")

@LauraBeatris LauraBeatris self-assigned this Oct 28, 2023
@LauraBeatris LauraBeatris changed the base branch from main to release/1.0.0 October 28, 2023 18:08
@LauraBeatris LauraBeatris changed the title Introduce SSO module improvements [WIP] Introduce SSO module improvements Oct 28, 2023
@LauraBeatris LauraBeatris force-pushed the update-sso-module branch 2 times, most recently from b5a6096 to bf32d12 Compare October 28, 2023 21:08
@LauraBeatris LauraBeatris force-pushed the update-sso-module branch 2 times, most recently from 4c81c86 to 90f37d6 Compare October 28, 2023 21:22
@LauraBeatris LauraBeatris force-pushed the update-sso-module branch 2 times, most recently from 431819d to f9f8054 Compare October 29, 2023 17:28
mix.exs Outdated Show resolved Hide resolved
@LauraBeatris LauraBeatris force-pushed the update-sso-module branch 2 times, most recently from b5e2768 to 3da041f Compare October 29, 2023 17:59
lib/workos/sso.ex Outdated Show resolved Hide resolved
@LauraBeatris LauraBeatris changed the title [WIP] Introduce SSO module improvements Introduce new SSO module and new tests structure Nov 9, 2023
@LauraBeatris LauraBeatris changed the title Introduce new SSO module and new tests structure Introduce new SSO module and tests structure Nov 9, 2023
@LauraBeatris LauraBeatris marked this pull request as ready for review November 9, 2023 22:13
@LauraBeatris LauraBeatris merged commit f5bcda8 into release/1.0.0 Nov 10, 2023
@LauraBeatris LauraBeatris deleted the update-sso-module branch November 10, 2023 01:32
LauraBeatris added a commit that referenced this pull request Dec 4, 2023
* Update `mix.exs`

* Add util module

* Add `Connection` struct

* Add `List` castable module

* Add `list_connections` method

* Add `delete_connection` method

* Add `get_connection` method

* Add draft for `get_authorization_url`

* Add `dialyxir` dependency

* Remove old SSO module

* Define logic for `get_authorization_url`

* Add `Profile` and `ProfileAndToken` response structs

* Add `get_profile` function

* Add basic layer for tests

* Add structs to `mix.exs`

* Fix guard on `get_authorization_url`

* Remove deprecated tests

* Add doc comments for parameter options of `get_authorization_url`

* Remove `Application.put_env` from `test_helper`

* Add draft test

* Fix extension of test files to `exs`

* Apply case for test config

* Define base URL for test

* Fix test

* Implement tests for `get_authorization_url`

* Define test for `get_profile_and_token`

* Implement tests for `get_profile_and_token`

* Implement tests for `get_profile`

* Implement test for `get_connection`

* Implement test for `list_connections`

* Rename `ClientMock` to `SSO.ClientMock`

* Implement test for `delete_connection`

* Fix return type for `delete_connection`

* Fix `mix credo` issues

* Update comment indentation

* Handle case where `get_authorization_url` is called without having the application config loaded

* Add validation for `redirect_uri`

* Include `client_id` on WorkOS Client

* Update livebook examples

* Fix connection struct

* Add `WorkOS.Empty`

* Remove `IO.inspect`
LauraBeatris added a commit that referenced this pull request Dec 20, 2023
* Introduce HTTP client and base URL as configuration options (#37)

* Add config modules

* Start to build behavior for HTTP client

* Add `Castable` module to define behavior for casting or transforming data

* Handle response

* Add HTTP methods to client behavior

* Add `TeslaClient` implementation

* Add comment to prod.exs to fix `mix format`

* Fix casing for `WorkOS` namespace

* Add `@deprecated` to `WorkOS.API`

* Fix test config

* Validate config

* Fix linter

* Add module for structured error response

* Extract env variables to separate variables

* Add livebook example (#38)

* Add `ISSUE_TEMPLATE.md` (#34)

* Permit `expires_in` param when creating passwordless session (#35)

Co-authored-by: Mark Tran <mark.tran@gmail.com>

* Start to build behavior for HTTP client

* Add `Castable` module to define behavior for casting or transforming data

* Handle response

* Add HTTP methods to client behavior

* Add `TeslaClient` implementation

* Add comment to prod.exs to fix `mix format`

* Fix casing for `WorkOS` namespace

* Add `@deprecated` to `WorkOS.API`

* Fix test config

* Validate config

* Fix linter

* Add livebook file

---------

Co-authored-by: Jordan Mackie <12185627+jmackie@users.noreply.github.com>
Co-authored-by: Mark Tran <mark.tran@gmail.com>

* Introduce new SSO module and tests structure (#39)

* Update `mix.exs`

* Add util module

* Add `Connection` struct

* Add `List` castable module

* Add `list_connections` method

* Add `delete_connection` method

* Add `get_connection` method

* Add draft for `get_authorization_url`

* Add `dialyxir` dependency

* Remove old SSO module

* Define logic for `get_authorization_url`

* Add `Profile` and `ProfileAndToken` response structs

* Add `get_profile` function

* Add basic layer for tests

* Add structs to `mix.exs`

* Fix guard on `get_authorization_url`

* Remove deprecated tests

* Add doc comments for parameter options of `get_authorization_url`

* Remove `Application.put_env` from `test_helper`

* Add draft test

* Fix extension of test files to `exs`

* Apply case for test config

* Define base URL for test

* Fix test

* Implement tests for `get_authorization_url`

* Define test for `get_profile_and_token`

* Implement tests for `get_profile_and_token`

* Implement tests for `get_profile`

* Implement test for `get_connection`

* Implement test for `list_connections`

* Rename `ClientMock` to `SSO.ClientMock`

* Implement test for `delete_connection`

* Fix return type for `delete_connection`

* Fix `mix credo` issues

* Update comment indentation

* Handle case where `get_authorization_url` is called without having the application config loaded

* Add validation for `redirect_uri`

* Include `client_id` on WorkOS Client

* Update livebook examples

* Fix connection struct

* Add `WorkOS.Empty`

* Remove `IO.inspect`

* Refactor `Organizations` module  (#44)

* Add skeleton for Organizations module

* Remove old `Organizations` module

* Add missing `object` key to connections domain

* Add response struct for organizations

* Implement functions for `Organization` module

* Add `create_organization` and `update_organization`

* Extract exceptions to separate modules

* Allow to call `list` functions without client and map args

* Implement tests for organizations

* Update Livebook examples

* Remove `Logger`

* Remove `WorkOS.Util` and fix timestamps

* Refactor `Portal` module (#45)

* Add basic modules

* Define function clauses

* Include implementation

* Add Portal link response struct

* Add portal client mock

* Implement tests

* Add example to Livebook

* Refactor `Webhooks` module (#46)

* Restructure modules

* Add `Event` struct to `mix.exs`

* Refactor `DirectorySync` module (#47)

* Add base modules

* Implement `get_directory`

* Implement `list_directories`

* Implement `delete_directory`

* Implement `Directory.User`

* Add tests for directory users

* Remove `WorkOS.Util`

* Add Livebook examples

* Rollback `Util` changes

* Remove `DateTime` from timestamps to match API reference

* Add missing `object` keys to response structs

* Remove WorkOS.Util

* Refactor `Passwordless` module (#48)

* Add base modules

* Implement functions

* Implement tests

* Remove `message` property

* Add `Events` module (#49)

* Add base modules

* Implement `list_events`

* Implement tests

* Add to Livebook

* Refactor `AuditLogs` module (#50)

* Add export response struct

* Add base modules

* Add implementation for `create_export`

* Add tests for `create_export`

* Add `get_export` method

* Add `add_event` method

* Add examples to Livebook

* Remove MFA module (#51)

* Add User Management API  (#53)

* Add draft for User Management module

* Add `Invitation` struct

* Add `User` struct

* Add User API methods

* Add methods from `Invitation` API

* Add `OrganizationMembership` API methods

* Add Password Reset API methods

* Add Email Verification API methods

* Add MFA response structs

* Add Multi-Factor API methods

* Add Magic Auth API methods

* Add Authentication API methods

* Add `get_authorization_url`

* Update Livebook

* Fixes `authorize` parameters

* Add Domain Verification API (#55)

* Remove legacy `WorkOS.API`

* Add `OrganizationDomain` struct

* Add Domain Verification API methods

* Add domain verification API methods

* Update README.md

* Format modules

* Fix `credo` issues

* Fix dialyzer issues

* Rename `DomainVerification` to `OrganizationDomains` (#56)

* Rename to `OrganizationDomains`

* Add to Livebook

* Remove `domain` option and add tests for error case

* Update workflow

* Bump to `1.0.0`

* Introduce Dialyzer artifacts

* Remove `:hackney`

* Update `elixirc_paths`

* Rollback `elixirc_paths`

* Import `ExUnit.Assertions` on mock files

* Update `plug_crypto`

* Update `jason`

* Remove support for oldest OTP version

* Update `dialyxir`

* Remove enum constants

* Update mock API keys

* Add deprecated `MFA` API module  (#58)

* Fix timestamp mapping

* Add deprecated response structs

* Add deprecated API

* Add tests

* Fix generate_link types

* Install `hackney`

* Fix query params

* Fix `list_groups` params

* Fix `send_session` route from Magic Link

* Pass `code` as keyword argument

* Fix `challenge_factor`

* Fix `get_organization` snippet from Livebook

* Add organization ID as parameter on `update_organization`

* Add `semaphore.yml`

* Fix `WorkOS.Empty` struct

* Fix `get_profile_and_token` snippet on Livebook

* Fix `get_profile` Livebook snippet

* Add experimental disclaimer back to README.md

* Rollback semaphore

* Rollback `elixir.yml` workflow due to branch policies

---------

Co-authored-by: Jordan Mackie <12185627+jmackie@users.noreply.github.com>
Co-authored-by: Mark Tran <mark.tran@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants