Skip to content

Commit

Permalink
feat(invitation): Adds invitation param for invitation only user logins
Browse files Browse the repository at this point in the history
  • Loading branch information
achedeuzot committed Oct 27, 2022
1 parent 05b51ce commit c12e68e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
- Support for `organization` and `invitation` query parameters
- Bumped dependencies

## v2.0.0 - 2021-08-14

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@
For an example implementation see the [Überauth Example](https://github.com/ueberauth/ueberauth_example) application.
## Learn about OAuth2
[OAuth2 explained with cute shapes](https://engineering.backmarket.com/oauth2-explained-with-cute-shapes-7eae51f20d38)
## Copyright and License
Expand Down
6 changes: 5 additions & 1 deletion lib/ueberauth/strategy/auth0.ex
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ defmodule Ueberauth.Strategy.Auth0 do
default_screen_hint: "",
default_login_hint: "",
default_organization: "",
# See https://auth0.com/docs/manage-users/organizations/configure-organizations/invite-members#specify-route-behavior
default_invitation: "",
allowed_request_params: [
:scope,
:state,
Expand All @@ -79,7 +81,8 @@ defmodule Ueberauth.Strategy.Auth0 do
:prompt,
:screen_hint,
:login_hint,
:organization
:organization,
:invitation
],
oauth2_module: Ueberauth.Strategy.Auth0.OAuth

Expand All @@ -105,6 +108,7 @@ defmodule Ueberauth.Strategy.Auth0 do
|> maybe_replace_param(conn, "screen_hint", :default_screen_hint)
|> maybe_replace_param(conn, "login_hint", :default_login_hint)
|> maybe_replace_param(conn, "organization", :default_organization)
|> maybe_replace_param(conn, "invitation", :default_invitation)
|> Map.put("state", conn.private[:ueberauth_state_param])
|> Enum.filter(fn {k, _} -> Enum.member?(allowed_params, k) end)
# Remove empty params
Expand Down
3 changes: 2 additions & 1 deletion test/strategy/auth0_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ defmodule Ueberauth.Strategy.Auth0Test do
"/auth/auth0?scope=profile%20address%20phone&audience=https%3A%2F%2Fexample-app.auth0.com%2Fmfa%2F" <>
"&connection=facebook&unknown_param=should_be_ignored" <>
"&prompt=login&screen_hint=signup&login_hint=user%40example.com" <>
"&organization=org_abc123"
"&organization=org_abc123&invitation=INVITE2022"
)
|> SpecRouter.call(@router)

Expand All @@ -86,6 +86,7 @@ defmodule Ueberauth.Strategy.Auth0Test do
assert conn.resp_body =~ ~s|scope=profile+address+phone|
assert conn.resp_body =~ ~s|state=#{conn.private[:ueberauth_state_param]}|
assert conn.resp_body =~ ~s|organization=org_abc123|
assert conn.resp_body =~ ~s|invitation=INVITE2022|
end

test "default callback phase" do
Expand Down

0 comments on commit c12e68e

Please sign in to comment.