Share via


How can i get Access Token in Sharepoint Framework(SPFX)?

Question

Thursday, August 3, 2017 11:51 AM

I want to get Access Token in SPFX solution but i didn't get any clue on that.

How can i do it?

All replies (3)

Friday, August 4, 2017 2:41 AM

Hi,

As per my knowledge, spfx running under the users context and can do whatever the user are allowed to do, so may I know why you need get Access Token?

You could check more details below.

https://github.com/SharePoint/sp-dev-docs/blob/master/docs/spfx/enterprise-guidance.md

If you want to call Microsoft Graph api, you could use ADAL to authenticate using the OAuth flow.

You could check below link for details.

https://dev.office.com/sharepoint/docs/spfx/web-parts/guidance/call-microsoft-graph-from-your-web-part

 

Best Regards,

Lee

Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact [email protected]


Tuesday, August 8, 2017 2:52 PM

Hi Lee,

Thanks for your answer.

What i want is i want to get TenantID by calling api  'https://xyz.sharepoint.com/_vti_bin/client.svc'.

But its not safe because as an anonymous user i can get tenantID by calling this api but it will gives 401 unauthorized status.

I want to call this API with AccessToken so it will provide status 200 if user is valid.

This is my requirement to get Access Token.

I refer your links but i think it will not help.

Do you have any better solution for this?

Thanks.


Monday, August 14, 2017 10:22 AM

Hi,

Below endpoint is public so you could use for anonymous users.

https://login.microsoftonline.com/yourtenant.onmicrosoft.com/.well-known/openid-configuration

Or, you could try to check whether current user is anonymous user, if anonymous user, skip to get tenantID.

Here are some links for your reference:

https://praneethmoka.wordpress.com/2012/01/12/some-useful-javascript-variablesfunctions-in-sharepoint/

https://lixuan0125.wordpress.com/2013/05/10/sharepoint-2013-get-current-user-loginname-using-jsom-rest/

Best Regards,

Lee

Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact [email protected]