GithubHelp home page GithubHelp logo

wmgdev / blazorgraphapi Goto Github PK

View Code? Open in Web Editor NEW
32.0 5.0 5.0 274 KB

Blazor Server App with Azure AD Authentication, that calls the Microsoft Graph API on-behalf of the signed-in user.

HTML 50.85% C# 29.21% CSS 19.93%
blazor microsoft-graph microsoft-graph-api microsoft-identity-platform blazor-server

blazorgraphapi's Introduction

BlazorGraphApi

Blazor Server App with Azure AD Authentication, that calls the Microsoft Graph API on-behalf of the signed-in user.

This code uses Microsoft.Indentity.Web

You will need to register your app in Azure and modify appsettings.json to include your details

{
  "AzureAd": {
    "Instance": "https://login.microsoftonline.com/",
    "Domain": "your.domain",
    "TenantId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "ClientId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "ClientSecret": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "ClientCertificates": [
    ],
    "CallbackPath": "/signin-oidc"
  },
  "DownstreamApi": {
    "BaseUrl": "https://graph.microsoft.com/beta",
    "Scopes": "user.read"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*"
}

Notes

Code has now been updated to include the new features, especially written for Blazor Server in Microsoft.Indentity.Web

This is a minimal example of calling MS Graph Api from Blazor Server. Microsoft.Identity.Web contains many other features which can be used in Blazor Server, including calling downstream WebApi and using incremental consent.

Hopefully these features will be rolled into the new project templates for Blazor in .NET 5

This example has evolved over time. Now that Microsoft.Identity.Web has improved and embraced Blazor Server, it's now pretty much a copy of the "blazorserver --auth SingleOrg --calls-graph" example app in their Repo

For more info refer to Microsoft.Indentity.Web

blazorgraphapi's People

Contributors

wmgdev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

blazorgraphapi's Issues

Scope - Refresh Token

Under app.settings, if "CalledApiScopes": "user.read offline_access" - is updated to include 'offline_access' how does a refresh token get acquired? Would this be true in this example? Does offline_access/refresh token work with Microsoft.Indentity.Web?

Logout does not work.

Very nice post!

When after LoginIn successfully and then click LogOut that will not work. The only way to make it work is by deleting the history from the explorer browsing data.

Is this problem related to your note?

Thanks

Trying to convert this sample to multi tenant

Does anyone have any ideas regarding updsating this sample to multi-tenant? Simply marking the app registration multi tenant is not enough. Thoughts? My ultimate goal is to add graph access and functionaility to an existing Blazor server application (multi-tenant AzureAD Auth).

Doesn't work when published to Azure

Have you been able to run this when deploying to azure? Runs great locally, however, when published as an App to Azure I get these errors:

Microsoft.Graph.ServiceException: Code: InvalidAuthenticationToken
Message: CompactToken parsing failed with error code: 80049217

Azure Signalr Service

First, thank you so much for the solid example.

When I add Azure Signalr Service to the project the /profile page constantly refreshes With each refresh it is calling the login.microsoftonline.com service. The profile information actually loads and displays on the page. Debug shows the following error on each refresh which isn't particularly helpful:

Exception thrown: 'Microsoft.Graph.ServiceException' in System.Private.CoreLib.dll System.Net.Http.HttpClient.Default.LogicalHandler: Information: Start processing HTTP request POST https://login.microsoftonline.com/{tenantid}/oauth2/v2.0/token System.Net.Http.HttpClient.Default.ClientHandler: Information: Sending HTTP request POST https://login.microsoftonline.com/{tenantid}/oauth2/v2.0/token System.Net.Http.HttpClient.Default.ClientHandler: Information: Received HTTP response after 201.8975ms - OK System.Net.Http.HttpClient.Default.LogicalHandler: Information: End processing HTTP request after 209.1404ms - OK

Any ideas? The same exact code works fine when using locally hosted SignalR.

Retrieve token on page load

Hi,

Thank you so much for the Graph solution on Blazor. Just one question, when I implement your profile page (profile.razor) on my project, everytime I navigate to it, the page redirects to a 'login.microsoftonline.com/common/...' URL, I suppose it was trying to request the token for a Graph call, then go back to the profile page with sufficient information of singed-in user. This is no big problem but a bit of hassle, as I expected the token to be retrieved straight away after signing in as an Office 365 user, and I just can call Graph at any places in my Blazor App without being redirected to MS Auth.
Can this step (retrieving token and have Graph ready) be done right at home page (index.razor) rendering? For example, inside OnInitializedAsync? I tried to put the profile API call into Index but I received an exception with ConsentHandler in the exception handling block.

Thank you!

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.