Ratn007 / AntBlaze

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Template of AntDesign Blazor

AntDesignWasmHostedPwaOidc

Blazor WebAssembly use AddOidcAuthentication() to call secured WebApis

0.Oidc Server (eg. IdentityServer4 with abp)

1.Client (ie. this repo)

        public static IEnumerable<Client> Clients =>
            new[]
            {
                new Client
                {
                    ClientId = "antBlazorApp.Client",
                    AllowedGrantTypes =   GrantTypes.Implicit ,

                    ClientSecrets =
                    {
                        new Secret("".Sha256())
                    },

                    RequirePkce = true,
                    RequireClientSecret = false,
                    AllowAccessTokensViaBrowser = true,
                    AllowedScopes =
                    {
                        IdentityServerConstants.StandardScopes.Email,
                        IdentityServerConstants.StandardScopes.OpenId,
                        IdentityServerConstants.StandardScopes.Profile,
                        "AntBlazorApp.ServerAPI"
                    },
                    RedirectUris =
                    {
                        "https://localhost:44326/authentication/login-callback"
                    },
                    PostLogoutRedirectUris =
                    {
                        "https://localhost:44326/authentication/logout-callback"
                    }
                },
            }

2. AddOidcAuthentication

            builder.Services.AddOidcAuthentication(options =>
            {
                builder.Configuration.Bind("Oidc", options.ProviderOptions); 
            });

appsettings.json

{
  "Oidc": {
    "Authority": "https://localhost:5001",
    "ClientId": "antBlazorApp.Client",
    "RedirectUri": "https://localhost:44326/authentication/login-callback",
    "PostLogoutRedirectUri": "https://localhost:44326/authentication/logout-callback",
    "ResponseType": "id_token token",
    "DefaultScopes": [
      "openid",
      "profile"
    ]
  } 
}

About

License:MIT License


Languages

Language:C# 73.8%Language:HTML 21.2%Language:JavaScript 2.3%Language:Less 1.7%Language:CSS 0.9%