我的asp.net Webforms网站已通过Azure进行身份验证,但我想知道如何集成Graph api,以便可以阅读更多用户配置文件。这是我的创业公司-谁能提供示例代码,例如,允许我从Azure读取用户管理器?
Imports Microsoft.Owin.Extensions
Imports Microsoft.Owin.Security
Imports Microsoft.Owin.Security.Cookies
Imports Microsoft.Owin.Security.OpenIdConnect
Imports Owin
Imports System.IdentityModel.Claims
Imports System.Threading.Tasks
Public Class Startup
Public Sub Configuration(ByVal app As IAppBuilder)
Dim appId = "xxxxxxxxxxxxxx"
Dim authority = "xxxxxxxxxxx"
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType)
app.UseCookieAuthentication(New CookieAuthenticationOptions())
app.UseOpenIdConnectAuthentication(New OpenIdConnectAuthenticationOptions With {
.ClientId = appId,
.Authority = authority,
.Notifications = New OpenIdConnectAuthenticationNotifications With {
.AuthorizationCodeReceived = Function(context)
Dim username As String = context.AuthenticationTicket.Identity.FindFirst(ClaimTypes.Name).Value
Dim authTicket As FormsAuthenticationTicket = New FormsAuthenticationTicket(1, username, DateTime.Now, DateTime.Now.AddMinutes(60), True, "")
Dim encryptedTicket As String = FormsAuthentication.Encrypt(authTicket)
context.Response.Cookies.Append(FormsAuthentication.FormsCookieName, encryptedTicket)
Return Task.FromResult(0)
End Function,
.AuthenticationFailed = Function(context)
context.HandleResponse()
context.Response.Write(context.Exception.Message)
Return Task.FromResult(0)
End Function
}
})
app.UseStageMarker(PipelineStage.Authenticate)
End Sub
End Class
就像@Thiago Custodio在评论中说的那样,vb.net现在没有样本。看看这个c# sample。或者,您可以在the REST API上方编写vb.net代码。