Skip to content

Commit a82582f

Browse files
authored
Adds prompt option to auth (#24)
1 parent 8bab530 commit a82582f

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
This library is designed for applications that use client credentials (application-only).
66

7-
Documentation can be found at [https://hexdocs.com/msg](https://hexdocs.com/msg).
7+
Documentation can be found at [https://hexdocs.pm/msg](https://hexdocs.pm/msg).
88

99
---
1010

@@ -37,6 +37,8 @@ client = Msg.Client.new(creds)
3737

3838
- Built on top of Req for HTTP requests
3939
- OAuth2 client credentials flow via oauth2
40+
- Graph API support for Users, Groups, Subscriptions, and Extensions
41+
- Automatic pagination handling
4042

4143
## License
4244

lib/msg/auth.ex

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ defmodule Msg.Auth do
113113
- `:redirect_uri` (required) - HTTPS URL where Microsoft redirects after auth
114114
- `:scopes` (required) - List of permission scopes to request
115115
- `:state` (optional) - Random string for CSRF protection (recommended)
116+
- `:prompt` (optional) - Controls sign-in behavior. Values:
117+
- `"select_account"` - Shows account picker (use different account than current session)
118+
- `"login"` - Forces credential entry (no SSO)
119+
- `"consent"` - Shows consent dialog after sign-in
120+
- `"none"` - No interactive prompt (fails if interaction required)
116121
117122
## Returns
118123
@@ -142,6 +147,7 @@ defmodule Msg.Auth do
142147
redirect_uri = Keyword.fetch!(opts, :redirect_uri)
143148
scopes = Keyword.fetch!(opts, :scopes)
144149
state = Keyword.get(opts, :state)
150+
prompt = Keyword.get(opts, :prompt)
145151

146152
query_params =
147153
[
@@ -152,6 +158,7 @@ defmodule Msg.Auth do
152158
response_mode: "query"
153159
]
154160
|> maybe_add_state(state)
161+
|> maybe_add_prompt(prompt)
155162
|> URI.encode_query()
156163

157164
"https://login.microsoftonline.com/#{tenant_id}/oauth2/v2.0/authorize?#{query_params}"
@@ -491,6 +498,9 @@ defmodule Msg.Auth do
491498
defp maybe_add_state(params, nil), do: params
492499
defp maybe_add_state(params, state), do: Keyword.put(params, :state, state)
493500

501+
defp maybe_add_prompt(params, nil), do: params
502+
defp maybe_add_prompt(params, prompt), do: Keyword.put(params, :prompt, prompt)
503+
494504
defp format_token_response(%AccessToken{} = token) do
495505
%{
496506
access_token: token.access_token,

0 commit comments

Comments
 (0)