From 9dc0943ed300a04b92ea80eda37bcfbbccb25079 Mon Sep 17 00:00:00 2001 From: JohnnyT Date: Tue, 2 Dec 2025 06:13:32 -0700 Subject: [PATCH] Adds prompt option to auth --- README.md | 4 +++- lib/msg/auth.ex | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 64b830c..78b8e68 100644 --- a/README.md +++ b/README.md @@ -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). --- @@ -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 diff --git a/lib/msg/auth.ex b/lib/msg/auth.ex index 5b92bd4..b1d2fc0 100644 --- a/lib/msg/auth.ex +++ b/lib/msg/auth.ex @@ -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 @@ -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 = [ @@ -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}" @@ -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,