stf icon indicating copy to clipboard operation
stf copied to clipboard

Add office365 via oauth2

Open HannanShaik opened this issue 9 years ago • 4 comments

I am trying to setup oAuth login with office 365 for STF.

stf local --auth-type oauth2 \
  --auth-options '[ 
    "--oauth-authorization-url", "https://login.windows.net/common/oauth2/authorize?resource=https%3A%2F%2Fgraph.microsoft.com",
    "--oauth-token-url", "https://login.windows.net/common/oauth2/token",
    "--oauth-userinfo-url", "**<What should be here?>**",
    "--oauth-client-id", "<my-client-id>",
    "--oauth-client-secret", "<my-secret>",
    "--oauth-callback-url", "https://stf.example.org/auth/oauth/callback",
    "--oauth-scope", "openid email"
  ]'

Wanted to understand what should be the --oauth-userinfo-url ?

Please help.

HannanShaik avatar Dec 09 '16 07:12 HannanShaik

Based on this and this, it should probably be:

https://login.windows.net/common/openid/userinfo

sorccu avatar Dec 09 '16 08:12 sorccu

Please report back with whether it worked for you and close the ticket.

sorccu avatar Dec 09 '16 08:12 sorccu

@sorccu Thanks I was able to set it up. However, getting this error in the logs

WRN/auth-oauth2 8996 [*] Missing email in profile

This is because the response doesn't contain the email field.

I am trying the modify the code and building locally now. Is there any other way?

HannanShaik avatar Dec 09 '16 11:12 HannanShaik

I solved the Missing email issue by locally modifying the code and building it.

This is the change i did.

  • Under lib/units/oauth2/

  • Modified index.js router method app.get( '/auth/oauth/callback' , function(req, res)

  • Added the below block.

      else if (req.user.unique_name) {
        res.redirect(urlutil.addParams(options.appUrl, {
          jwt: jwtutil.encode({
            payload: {
              email: req.user.unique_name
            , name: req.user.unique_name.split('@', 1).join('')
            }
          , secret: options.secret
          , header: {
              exp: Date.now() + 24 * 3600
            }
          })
        }))
      }

Then it worked!

HannanShaik avatar Dec 09 '16 13:12 HannanShaik