Office365 accesstoken
No edit summary
No edit summary
Line 22: Line 22:
We can now formulate the request for (1) a code (lives very short time) - we will then use this code to get an (2)access token (lives an hour) and a (2)refresh token (lives very long - often until revoked).
We can now formulate the request for (1) a code (lives very short time) - we will then use this code to get an (2)access token (lives an hour) and a (2)refresh token (lives very long - often until revoked).


  'https://login.microsoftonline.com/'+SysSingleton.oclSingleton.Office365TennantId+'/oauth2/v2.0/authorize?
  '<nowiki>https://login.microsoftonline.com/'+SysSingleton.oclSingleton.Office365TennantId+'/oauth2/v2.0/authorize</nowiki>?
  client_id='+SysSingleton.oclSingleton.Office365ClientId+'
  client_id='+SysSingleton.oclSingleton.Office365ClientId+'
  &response_type=code
  &response_type=code
Line 28: Line 28:
  &response_mode=query
  &response_mode=query
  &scope='+SysSingleton.oclSingleton.UrlEncode( SysSingleton.oclSingleton.Office365Scope,false)+'
  &scope='+SysSingleton.oclSingleton.UrlEncode( SysSingleton.oclSingleton.Office365Scope,false)+'
  &state='+SysSingleton.oclSingleton.UrlEncode('<nowiki>http://localhost:5020/App#/AzureAuthorize/$null$',false</nowiki>)
  &state='+SysSingleton.oclSingleton.UrlEncode('http://localhost:5020/App#/AzureAuthorize/$null$',false)
Note the last query parameter: state - this is just runtripped for us - we use it to know where to redirect once we have the accesstoken.
 
You can use Tagged value DataIsLink and have the above url in a ViewModel column, or you can use the selfVM.NavigateURL in an action.

Revision as of 16:03, 24 April 2023

Background : https://learn.microsoft.com/en-us/graph/auth-v2-user

Office365 contains the GraphAPI that be used to access sharepoint documents, calendars,emails etc

2023-04-24 17h45 47.png

What you need to do on the Azure side of this (also called the tennant by Microsoft) is to do an App_Registration, you do this in https://Portal.Azure.com.

From here you will need:

Client id, a guid string - put this in SysSingleton.Office365ClientId

tennant id, a guid string - put this in SysSingleton.Office365TennantId

Client secret, SysSingleton.Office365ClientSecret

You will also need to Grant your app-registration access to particular interfaces in office365 (allowed to see email or not, allowed to see sharepoint lists or not)

Image (3).png

Once you are ready to "log on" or Authorize you must say what scope THIS particular session should see : scope looks like this, its a space delimited string:

offline_access User.Read Sites.Read.All

Put this value in SysSingleton.Office365Scope

We can now formulate the request for (1) a code (lives very short time) - we will then use this code to get an (2)access token (lives an hour) and a (2)refresh token (lives very long - often until revoked).

'https://login.microsoftonline.com/'+SysSingleton.oclSingleton.Office365TennantId+'/oauth2/v2.0/authorize?
client_id='+SysSingleton.oclSingleton.Office365ClientId+'
&response_type=code
&redirect_uri='+SysSingleton.oclSingleton.UrlEncode( SysSingleton.oclSingleton.Office365Redirect,false)+'
&response_mode=query
&scope='+SysSingleton.oclSingleton.UrlEncode( SysSingleton.oclSingleton.Office365Scope,false)+'
&state='+SysSingleton.oclSingleton.UrlEncode('http://localhost:5020/App#/AzureAuthorize/$null$',false)

Note the last query parameter: state - this is just runtripped for us - we use it to know where to redirect once we have the accesstoken.

You can use Tagged value DataIsLink and have the above url in a ViewModel column, or you can use the selfVM.NavigateURL in an action.

This page was edited 49 days ago on 03/19/2024. What links here