google / google-authenticator-libpam

Apache License 2.0
1.8k stars 286 forks source link

Can google authenticator send email to user with link to qr code? #44

Open ThomasHabets opened 7 years ago

ThomasHabets commented 7 years ago

From @Infectsoldier on January 12, 2016 9:20

Hello. I need to generate link and send it to user with email address, or show link when user do first login in to ssh. Is this possible?

OS: Centos 6.x

Copied from original issue: google/google-authenticator#534

ThomasHabets commented 7 years ago

Email

How would you know the email address to use? (in the general case) You can do this by scripting pretty easily today.

Show link at first login

This would be possible. A pull request to do so may be accepted if it looks good.

There is the problem of "what if the user forgot to scan the QR code the first time?" does occur to me though.

ThomasHabets commented 7 years ago

From @Infectsoldier on January 12, 2016 12:9

User will give email to admin, and admin run google authenticator from this user and with email For script: I use ansible for creating user and running google authenticator. And it can parse log and send link to user by email. But we need to send email using google authenticator not ansible or other stuff

If user do not scan QR code, admin can re-run google authenticator for that user, and after next login, user will saw that link

ThomasHabets commented 7 years ago

From @ThiefMaster on January 12, 2016 12:58

The most common way to enable 2FA is to require the user to enter a code from the app to finally enable it. That way he proved that he set it up, i.e. he won't lock himself out.

ThomasHabets commented 7 years ago

@ThiefMaster oh yeah, that'd do it.

@Infectsoldier what do you mean by "we need to send email using google authenticator"? Sending email does not belong here. All you need to script is to send out the QR code for otpauth://totp/foobar?secret=ABCDEF where ABCDEF can be found in the user's ~/.google_authenticator

ThomasHabets commented 7 years ago

I've created #536 to track the non-email feature.

ThomasHabets commented 7 years ago

From @pantsman0 on February 23, 2016 11:41

@Infectsoldier something like this?

#!/bin/bash

if [[ ! -e ~/.google_authenticator ]];
then
    echo "If you lose your One-Time Password, you will not be able to log in.";

    # inspired by the answer by Dennis Williamson
    # http://stackoverflow.com/a/1885534
    read -p  "Do you want to create your One-Time Password now? [y/n] " -n 1 -r c;
    echo;

    if [[ ! $c =~ ^[Yy]$ ]];
    then
        exit 1
    fi
    google-authenticator -t -d -f -i "My Issuer" -l "My Label" -u -w3
fi

If you added this to the /etc/skel/.bash_login it will continue to prompt a user when they first open a bash shell.

If you leave bash as a default shell for CentOS this should meet needs, and it will continue to prompt or log out a user until they accept.

ThomasHabets commented 7 years ago

From @Infectsoldier on February 23, 2016 12:2

@pantsman0 thanks. But i already use ansible. Ansible generate link and send it to user email

ThomasHabets commented 7 years ago

From @pantsman0 on February 23, 2016 12:45

my bad, I meant to say that my comment is only answering the "show link when user do first login in to ssh", as Thomas has already opened a new issue (#536) to address the email option.

ThomasHabets commented 7 years ago

The non-email option, you mean.

ThomasHabets commented 7 years ago

@Infectsoldier

And it can parse log and send link to user by email. But we need to send email using google authenticator not ansible or other stuff

Google authenticator the CLI tool? Why? If you have the email address, why not just send it yourself?