Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

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

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

---

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

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

## License

Expand Down
10 changes: 10 additions & 0 deletions lib/msg/auth.ex
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ defmodule Msg.Auth do
- `:redirect_uri` (required) - HTTPS URL where Microsoft redirects after auth
- `:scopes` (required) - List of permission scopes to request
- `:state` (optional) - Random string for CSRF protection (recommended)
- `:prompt` (optional) - Controls sign-in behavior. Values:
- `"select_account"` - Shows account picker (use different account than current session)
- `"login"` - Forces credential entry (no SSO)
- `"consent"` - Shows consent dialog after sign-in
- `"none"` - No interactive prompt (fails if interaction required)

## Returns

Expand Down Expand Up @@ -142,6 +147,7 @@ defmodule Msg.Auth do
redirect_uri = Keyword.fetch!(opts, :redirect_uri)
scopes = Keyword.fetch!(opts, :scopes)
state = Keyword.get(opts, :state)
prompt = Keyword.get(opts, :prompt)

query_params =
[
Expand All @@ -152,6 +158,7 @@ defmodule Msg.Auth do
response_mode: "query"
]
|> maybe_add_state(state)
|> maybe_add_prompt(prompt)
|> URI.encode_query()

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

defp maybe_add_prompt(params, nil), do: params
defp maybe_add_prompt(params, prompt), do: Keyword.put(params, :prompt, prompt)

defp format_token_response(%AccessToken{} = token) do
%{
access_token: token.access_token,
Expand Down