Coder Social home page Coder Social logo

Get User Name? about office-js-helpers HOT 3 CLOSED

officedev avatar officedev commented on June 5, 2024
Get User Name?

from office-js-helpers.

Comments (3)

WrathOfZombies avatar WrathOfZombies commented on June 5, 2024

@ostorefice Thanks 👍

There's no way to get user name in this library as we don't control the scope/API implementations of each of the Auth providers. It would add additional maintenance costs and hence I suggest using the Graph API to get that information with the token you obtained.

See more info here: https://developer.microsoft.com/en-us/graph/

Here's a sample on how to use Office Helpers with graph: https://github.com/microsoftgraph/javascript-officeuifabric-peoplepicker-sample/blob/master/PeoplePicker.html#L163

from office-js-helpers.

azolson avatar azolson commented on June 5, 2024

If, by username you mean the UPN then this is one of the returned values (I'm using the /me endpoint when querying msft graph)

I'm using react, but the following code is probably quite obvious, and provides me with the UPN (the token's scope used for this request is https://graph.microsoft.com/User.Read):

export function getMicrosoftUserProfile(token){
    return function(dispatch){
        request
            .get(`${constants.MSFT_DATA_API}/me/`)
            .set('Accept', 'application/json')
            .set('Authorization', `Bearer ${token.access_token}`)
        .then(
            res => {
                if (res.status >= 200 && res.status < 300) {
                    dispatch(setUserInformation(res.body))
                    console.log(res.body)
                }
            }
        )
        .catch((err) => {
            console.log(err.status + ': ' + err.response)
          })
    }
}

returned values:

businessPhones : []
displayName : "Marvin Martian"
givenName : "Marvin"
id : "4b60d56e-4edd-4b4c-873a-f0e6d1112345"
jobTitle : "Chief Technology Officer"
mail : "[email protected]"
mobilePhone : "+44 12345656"
officeLocation : null
preferredLanguage :"en-GB"
surname : "Martian"
userPrincipalName : "[email protected]"

from office-js-helpers.

WrathOfZombies avatar WrathOfZombies commented on June 5, 2024

@azolson yes the username would be the UPN.

from office-js-helpers.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.