Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support identity openapi standard #189

Open
shps951023 opened this issue Jun 9, 2024 · 4 comments
Open

Support identity openapi standard #189

shps951023 opened this issue Jun 9, 2024 · 4 comments

Comments

@shps951023
Copy link
Member

No description provided.

@shps951023
Copy link
Member Author

shps951023 commented Jun 9, 2024

login

https://github.com/dotnet/aspnetcore/blob/main/src/Identity/Core/src/IdentityApiEndpointRouteBuilderExtensions.cs

Image

Image

{
  "tokenType": "Bearer",
  "accessToken": "CfDJ8JQ6UejBIoRIkUpEJR_892dspJ-O86oy40XNFLGLz60aayDqXmN_iBJbCi-XHSdECCl0wNlmk_z7jauKDhubjbvnzLIR3i5B4tJW81eLnGgeTlyMtKyeFi7Cuhtctsw2cgyyCdf18V46yYGtLfYMPdupbrJSyBFMhSpRwUjOPs1k-0CisA3i3wlv9G0wNj4n8S1LXQYzxiF5RqjAye_kqgfHtmJy3KY4_-PVTjaLyBT52v1a34ZLvWlcV_oHd32mgg9RRk_T_CSWCag2wL1XYlEP2MHQ61uOdpE_z-LkuxgOCpoubelPiaWLUZhyQySi256TyjW6DcDOOvqsrhu0-gkUWeykJKD0S80Q4bRXJxUgqFUFz_2u5M0ZnwxC4Q7BGrfCe5r9Yck8HbrbB7yddEBRUDeaVdMPSrt8ckhvZb55DwG1gmvri4L0ElbpUlrfS5srr6vDc-k6ERvwF00f4lS6g6ZC900xJuXTsdATVzWXUpnsYhLZhJNP89PNy0QFwF8F_x7vxHZzEDDP5QTOh1pP4hem3C4ubIIqiA23Hf-HjtuHvLMq7CuMpOpW9RnGucu8ut3hLyi6eWwa9wopoeVsRinbM8NvfnPtFfzAghxi9MaEPT57oFw3UlDgU8ASb4TXzx2AwRYeq0rrbq6YCnp9ZNmTZJzH8DaLkJE8flz9Wqk-ekjlsmK3MDx7qgdcnxuXTbs0k2c-P0XKL4WzgW8",
  "expiresIn": 3600,
  "refreshToken": "CfDJ8JQ6UejBIoRIkUpEJR_892eLslb7k4rBSVMLeyiE_Rc_fU3afrhLQpjI_m8PKfVbwK7PBjvY-_5gc_87F--SyHdiVaTAVbzwinMN9asPc4XLNuiPM6YsUBI1k6syOYaMRkhlkgJbFZ_YWEyeIcPxXzfVSqbWQE4rjhINhGFVWZz2qUlHjuBxQ6o5XcxUNOaKOHiyPleorR_keLdSXI8sY7706e10xqAhwVnhcJ_YLZItRdWAhYXPHrK2q994BiseITejRouNHhs4qfrgDI1JPnyIR8fWnrXoONBH3s0R94nqgr6AB2YIe6QvyFtiIOnI7_Q8ZuGlVs5OqMgHqYHPAWRehoJ9JlyQ4ZuqxBqLEDcu4H0YJT8WwfcO9k1-_2b7grgCzF5GX1D4_-juJu91pYuXR7QuQNcGPVIPVkLdVQMy18m-J87zGqhcL2xi3UC8cigvp6gvpKiU2ideIvPZtmYsJSulb1DTnh5FyfdJGt4nwuJiZYl7NJqxQIE-yyJPqse3c3t1nKCU9AUEFiNRLq5friuvNBCiZ_ich_bRIrbeJBHr-qHOQRzQqDXp62UrryVVVdE30I8YRsD9FmcLhKMxJofiez_ASFZvtWMzsD3DLKS5_he9oGW2ncQlGbBwoqVzB3-ft__WskSm0VurOeBsSw99cS0VbZ3VMRGs8VRkFnPuGukw-Yj4Rkx0JRm4OwAOvikl80w-9hccdNSBfpA"
}

Image

@shps951023 shps951023 changed the title Support identity openapi Support identity openapi standard Jun 9, 2024
@shps951023
Copy link
Member Author

Register

{
  "type": "https://tools.ietf.org/html/rfc9110#section-15.5.1",
  "title": "One or more validation errors occurred.",
  "status": 400,
  "errors": {
    "DuplicateUserName": [
      "Username '[email protected]' is already taken."
    ]
  }
}

@shps951023
Copy link
Member Author

    private static IdentityBuilder AddIdentityApiEndpoints<TUser, TContext>(IServiceCollection services)
        where TUser : class, new()
        where TContext : DbContext
    {
        return services.AddDbContext<TContext>((sp, options) => options.UseSqlite(sp.GetRequiredService<SqliteConnection>()))
            .AddIdentityApiEndpoints<TUser>().AddEntityFrameworkStores<TContext>();
    }

@shps951023
Copy link
Member Author

    public static IdentityBuilder AddIdentityApiEndpoints<TUser>(this IServiceCollection services, Action<IdentityOptions> configure)
        where TUser : class, new()
    {
        ArgumentNullException.ThrowIfNull(services);
        ArgumentNullException.ThrowIfNull(configure);

        services
            .AddAuthentication(IdentityConstants.BearerAndApplicationScheme)
            .AddScheme<AuthenticationSchemeOptions, CompositeIdentityHandler>(IdentityConstants.BearerAndApplicationScheme, null, compositeOptions =>
            {
                compositeOptions.ForwardDefault = IdentityConstants.BearerScheme;
                compositeOptions.ForwardAuthenticate = IdentityConstants.BearerAndApplicationScheme;
            })
            .AddBearerToken(IdentityConstants.BearerScheme)
            .AddIdentityCookies();

        return services.AddIdentityCore<TUser>(configure)
            .AddApiEndpoints();
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

No branches or pull requests

1 participant