This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.AspNetCore.Authentication.Cookies; | |
using Microsoft.AspNetCore.Authentication.OpenIdConnect; | |
using Microsoft.IdentityModel.Protocols.OpenIdConnect; | |
// Connect to Asgardeo for authentication. | |
builder.Services.AddAuthentication(options => { | |
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; | |
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme; | |
}) | |
.AddCookie() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.Extensions.Configuration; | |
IConfiguration Configuration = new ConfigurationBuilder() | |
.SetBasePath(AppDomain.CurrentDomain.BaseDirectory) | |
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) | |
.Build(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Logging": { | |
"LogLevel": { | |
"Default": "Information", | |
"Microsoft.AspNetCore": "Warning" | |
} | |
}, | |
"Asgardeo": { | |
"Tenant": "thivi", | |
"ClientID": "YegzRZID4Tv_yJfb_dob2R5Z7hMa", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var options = new OidcClientOptions | |
{ | |
Authority = $"https://api.asgardeo.io/t/{ConfigurationManager.AppSettings["Tenant"]}/oauth2/token", | |
ClientId = ConfigurationManager.AppSettings["ClientId"], | |
ClientSecret = ConfigurationManager.AppSettings["ClientSecret"], | |
Scope = "openid profile groups", | |
RedirectUri = ConfigurationManager.AppSettings["RedirectURI"], | |
PostLogoutRedirectUri = ConfigurationManager.AppSettings["RedirectURI"], | |
Browser = new WebView(), | |
Policy = new Policy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_client = new OidcClient(options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_authenticationResult = await _client.LoginAsync(new LoginRequest()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var logoutRequest = new LogoutRequest | |
{ | |
IdTokenHint = _authenticationResult.IdentityToken, | |
BrowserDisplayMode = IdentityModel.OidcClient.Browser.DisplayMode.Hidden | |
}; | |
LogoutResult result = await _client.LogoutAsync(logoutRequest); | |
NameValueCollection queryDict = System.Web.HttpUtility.ParseQueryString(new Uri(result.Response.ToString()).Query.ToString()); | |
if(queryDict.Get("error") == null) | |
{ | |
_authenticationResult = null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// When the app was activated by a Protocol (custom URI scheme), forwards | |
// the URI to the SystemBrowser through a static method. | |
if (args.Kind == ActivationKind.Protocol) | |
{ | |
// Extracts the authorization response URI from the arguments. | |
ProtocolActivatedEventArgs protocolArgs = (ProtocolActivatedEventArgs)args; | |
Uri uri = protocolArgs.Uri; | |
WebView.ProcessResponse(uri); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class WebView : IBrowser | |
{ | |
public static TaskCompletionSource<BrowserResult> inFlightRequest; | |
public Task<BrowserResult> InvokeAsync(BrowserOptions options, CancellationToken cancellationToken = default) | |
{ | |
inFlightRequest = new TaskCompletionSource<BrowserResult>(); | |
var currentAppView = ApplicationView.GetForCurrentView(); | |
RunOnNewView(async () => { | |
var newAppView = CreateApplicationView(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<uap:Extension Category="windows.protocol"> | |
<uap:Protocol Name="sample"> | |
<uap:Logo>Assets\Icon.png</uap:Logo> | |
<uap:DisplayName>Sample</uap:DisplayName> | |
</uap:Protocol> | |
</uap:Extension> |