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

Add option to show device code to user directly #60

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions debian/pam_aad.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"id": "{{group_id}}"
},
"smtp_server": "{{smtp_server}}",
"email": "true",
"tenant": {
"name": "{{organization}}.onmicrosoft.com",
"address": "{{organization_email_address}}"
Expand Down
25 changes: 20 additions & 5 deletions pam_aad.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
#define SUBJECT "Your one-time passcode for signing in via Azure Active Directory"
#define TTW 5 /* time to wait in seconds */
#define USER_AGENT "azure_authenticator_pam/1.0"
#define USER_PROMPT "\n\nEnter the code at https://aka.ms/devicelogin."
#define USER_PROMPT "Enter the code at https://aka.ms/devicelogin."
#define USER_PROMPT_ENTER "Enter the code at https://aka.ms/devicelogin, then press enter."

#ifndef _AAD_EXPORT
#define STATIC static
Expand Down Expand Up @@ -378,9 +379,10 @@ STATIC int notify_user(const char *to_addr, const char *from_addr, const char *m
return (int) res;
}

STATIC int azure_authenticator(const char *user)
STATIC int azure_authenticator(pam_handle_t * pamh, const char *user)
{
jwt_t *jwt;
bool enable_email = false;
bool debug = DEBUG;
const char *client_id, *group_id, *tenant,
*domain, *u_code, *d_code, *ab_token, *tenant_addr, *smtp_server;
Expand Down Expand Up @@ -453,6 +455,10 @@ STATIC int azure_authenticator(const char *user)
fprintf(stderr, "error with Domain in JSON\n");
return ret;
}
if (json_object_get(config, "email"))
if(strcmp(json_string_value(json_object_get(config, "email")),"true") == 0)
enable_email = true;


sds user_addr = sdsnew(user);
user_addr = sdscat(user_addr, "@");
Expand All @@ -467,8 +473,17 @@ STATIC int azure_authenticator(const char *user)

sds prompt = sdsnew(CODE_PROMPT);
prompt = sdscat(prompt, u_code);
prompt = sdscat(prompt, USER_PROMPT);
notify_user(user_addr, tenant_addr, prompt, smtp_server, debug);
prompt = sdscat(prompt, "\n");

if(enable_email){
prompt = sdscat(prompt, USER_PROMPT);
prompt = sdscat(prompt, "\n");
notify_user(user_addr, tenant_addr, prompt, smtp_server, debug);
} else {
prompt = sdscat(prompt, USER_PROMPT_ENTER);
prompt = sdscat(prompt, "\n");
(void) pam_prompt(pamh, PAM_PROMPT_ECHO_OFF, NULL, prompt);
}

auth_bearer_request(&data, client_id, tenant, d_code, json_data,
debug);
Expand Down Expand Up @@ -502,7 +517,7 @@ PAM_EXTERN int pam_sm_authenticate(pam_handle_t * pamh, int flags,
return ret;
}

if (azure_authenticator(user) == 0)
if (azure_authenticator(pamh, user) == 0)
return PAM_SUCCESS;

return ret;
Expand Down