You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We'd want to be able to set which Microsoft graph endpoint to use (v1.0, Beta, but also national clouds) from the configuration, or programmatically. For instance in the appsettings.json
{
"AzureAd": {
"Instance": "https://login.microsoftonline.com/",
"Domain": "qualified.domain.name",
"TenantId": "22222222-2222-2222-2222-222222222222",
"ClientId": "11111111-1111-1111-11111111111111111",
"ClientSecret": "[Copy the client secret added to the app from the Azure portal]",
"CallbackPath": "/signin-oidc"
},
"GraphBeta": {
"CalledApiUrl": "https://graph.microsoft.com/beta",
"CalledApiScopes": "user.read"
},
}
And be able to reference them in a CallsMicrosoftGraph method that would be called under CallsWebApi() or under AddMicrosoftIdentityWebApp or AddMicrosoftIdentityWebApi (to be decided)
Add a CalledApiOptions class, which will also be used for Downstream APIs (hence the HttpMethod which does not seem to be used here)
/// <summary>/// Options passed-in to call web APIs (Microsoft Graph or another API)./// </summary>publicclassCalledApiOptions{/// <summary>/// Base URL for the called Web API. For instance <c>"https://graph.microsoft.com/v1.0/".</c>./// </summary>publicstringCalledApiBaseUrl{get;set;}="https://graph.microsoft.com/v1.0/";/// <summary>/// Space separated scopes used to call the Web API./// For instance "user.read mail.read"./// </summary>publicstring?CalledApiScopes{get;set;}=null;/// <summary>/// Http method used to call this API (by default Get)./// </summary>publicHttpMethodHttpMethod{get;set;}=HttpMethod.Get;}
Add the TokenAcquisitionCredentialProvider class which is currently shipped in the templates.
Reference the Microsoft.Graph NuGet package from the Microsoft.Identity.Web project
Remove references to the Microsoft.Graph NuGet package from all the test apps that use it
Add a MicrosoftGraphServiceExtensions inspired by the one shipped in the templates, but applied to
/// <summary>/// Extensions methods on a MicrososoftAppCallingWebApiAuthenticationBuilder builder/// to add support to call Microsoft Graph./// </summary>publicstaticclassMicrosoftGraphServiceExtensions{/// <summary>/// Add support to calls Microsoft graph. From a named option and a configuration section/// </summary>/// <param name="builder">Builder.</param>/// <param name="configurationSection">Configuraiton section.</param>/// <returns>The builder to chain.</returns>publicstaticMicrososoftAppCallingWebApiAuthenticationBuilderCallsMicrosoftGraph(thisMicrososoftAppCallingWebApiAuthenticationBuilderbuilder,IConfigurationSectionconfigurationSection){// Todo chain with the one with delegates}/// <summary>/// Add support to calls Microsoft graph. From a base graph Url and a default scope./// </summary>/// <param name="builder">Builder.</param>/// <param name="graphBaseUrl">Named instance of option.</param>/// <param name="defaultScopes">Configuration section.</param>/// <returns>The builder to chain.</returns>publicstaticMicrososoftAppCallingWebApiAuthenticationBuilderCallsMicrosoftGraph(thisMicrososoftAppCallingWebApiAuthenticationBuilderbuilder,stringgraphBaseUrl="https://graph.microsoft.com/v1.0",stringdefaultScopes="user.read"){// Todo chain with the one with delegates}/// <summary>/// Add support to calls Microsoft graph. From a named options and a configuraiton method./// </summary>/// <param name="builder">Builder.</param>/// <param name="configureOptions">Method to configure the options.</param>/// <returns>The builder to chain.</returns>publicstaticMicrososoftAppCallingWebApiAuthenticationBuilderCallsMicrosoftGraph(thisMicrososoftAppCallingWebApiAuthenticationBuilderbuilder,Action<CalledApiOptions>configureOptions);
The override with delegates will need to add the following services:
jmprieur
changed the title
[Feature Request] CallsMicrosoftGraph exposes the Graph SDK
[Feature Request] CallsMicrosoftGraph in Startup.cs enables usage of the Graph SDK in controllers / Razor / Blazor pages
Aug 10, 2020
Fixes#427
Add the `MicrosoftGraphOptions`, `MicrosoftGraphServiceExtensions`, `TokenAcquisitionCredentialProvider` (coming from the Blazor sample)
Update the test apps that where using graph
- WebAppCallsMicrosoftGraph
- BlazorServerCallsGraph
Updating the samples requires the following:
- remove the package reference to the Microsoft Graph SDK, as it is no longer needed in the sample (brought by Microsoft.Identity.Web)
- update the appsettings.Json to use the new names for the settings (`BaseUrl` and `Scopes`)
- remove the implementation which was so far in the sample for the MicrosoftGraphService and it's token provider (this was the implementation brought by the project templates)
- in startup.cs, remove the calls to `services.AddMicrosoftGraph(scopes, Configuration.GetValue<string>("CalledApi:CalledApiUrl"));` and replace it by what we agreed on with Damien:
```CSharp
.EnableTokenAcquisitionToCallDownstreamApi()
.AddMicrosoftGraphServiceClient(Configuration.GetSection("GraphBeta"))
```
Co-authored-by: pmaytak <34331512+pmaytak@users.noreply.github.com>
Co-authored-by: Jenny Ferries <jeferrie@microsoft.com>
Issue
Today the template introduce files to easy calling MIcrosoft Graph that would benefit from being productized in the library
Spec
See #431
We'd want to be able to set which Microsoft graph endpoint to use (v1.0, Beta, but also national clouds) from the configuration, or programmatically. For instance in the appsettings.json
And be able to reference them in a
CallsMicrosoftGraph
method that would be called underCallsWebApi()
or underAddMicrosoftIdentityWebApp
orAddMicrosoftIdentityWebApi
(to be decided)We'll also provide a simple override that use the default (https://graph.microsoft.com/v1.0 and "user.read")
And an override that offers a delegate:
In the controller or a Razor page, or a Blazor page, the GraphServiceClient will be injected by dependency injection and simply used.
Proposed design / work to be done
TokenAcquisitionCredentialProvider
class which is currently shipped in the templates.Microsoft.Graph
NuGet package from the Microsoft.Identity.Web projectMicrosoft.Graph
NuGet package from all the test apps that use itMicrosoftGraphServiceExtensions
inspired by the one shipped in the templates, but applied toThe override with delegates will need to add the following services:
builder.Services.AddOptions<CalledApiOptions>().Configure(configureOptions)
)builder.Services.AddTokenAcquisition(true)
)Update the test apps to use this new way of adding Graph (in the Startup.cs / appsettings.json)
Update the project templates to use this new way of adding Graph (and remove the references to the Microsoft.Graph NuGet package)
The text was updated successfully, but these errors were encountered: