Add office365 via oauth2
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.
Please report back with whether it worked for you and close the ticket.
@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?
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.jsrouter methodapp.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!