robocorp / rpaframework

Collection of open-source libraries and tools for Robotic Process Automation (RPA), designed to be used with both Robot Framework and Python
https://www.rpaframework.org/
Apache License 2.0
1.15k stars 224 forks source link

Oauth2 from Microsoft #925

Closed matheusbarcelos closed 1 year ago

matheusbarcelos commented 1 year ago

I need to develop the login in a test automation, where there is authentication in the second factor (oauth2) from Microsoft(Microsoft Authenticator). I tried to develop using the RPA.MFA library, but I wasn't successful. Studying the documentation I did not find any similar example. Kindly, has anyone ever needed to implement something similar? Any libraries to recommend?

cmin764 commented 1 year ago

If this is not really an issue with the library, I recommend closing this and opening a new thread on our troubleshooting Forum.

matheusbarcelos commented 1 year ago

Hello @cmin764 . Thank you for the informations

I checked the examples but didn't find a scenario similar to what I needed.

Our second factor authentication works as follows: After entering user and password, the Microsoft Authenticator application receives a notification where it is possible to authorize or reject the login.

I followed the documentation present at https://robocorp.com/docs/libraries/rpa-framework/rpa-mfa, but I didn't find any examples that fit. I see that I need to authorize the user, or get the access code to report at login.

Kindly, do you have any example similar to this case? Do you know if it is possible to automate login this way?

cmin764 commented 1 year ago

Yes, please read the detailed instructions of this example robot given the Microsoft section. Then download the bot and run this Microsoft task: Microsoft MFA which logins with user & password, then chooses to sign in through another way, then it submits the OTP code automatically without relying on your mobile Authenticator app anymore.

Robot code example:

Microsoft MFA
    # Login with username and password.
    Open Available Browser    https://mysignins.microsoft.com/
    Input Text When Element Is Visible    name:loginfmt    ${SECRETS}[microsoft_usr]
    ${submit_locator} =    Set Variable    idSIButton9
    Click Button When Visible    ${submit_locator}
    ${password_locator} =    Set Variable    passwd
    Wait Until Element Is Visible    ${password_locator}
    Input Password    ${password_locator}    ${SECRETS}[microsoft_pwd]
    Click Button When Visible    ${submit_locator}

    # Proceed to OTP input.
    Click Element When Visible    signInAnotherWay
    # Click Element If Visible    idA_SAASTO_SendCode
    Click Element When Visible    //div[contains(text(), 'verification code')]

    # Input OTP.
    Use Mfa Secret From Vault    MFA    microsoft_secret
    ${code} =    Get Time Based Otp
    Input Text When Element Is Visible    name:otc    ${code}
    Click Button When Visible    idSubmit_SAOTCC_Continue

    # Remember sign-in.
    Click Element When Visible    //span[contains(text(), 'show this')]
    Click Button When Visible    ${submit_locator}

    Go To    https://outlook.office.com/mail/

Make sure you have a correct online / local Vault setup. (remove/rename env.json file when relying on an online Vault from Control Room (recommended))


If you still run into trouble, please submit a new post on our Forum and post the log.html and a screenshot to the error trace if any.