数据库填充数据:
insert into oauth2_registered_client( id, client_id, client_id_issued_at, client_secret, client_secret_expires_at, client_name, client_authentication_methods, authorization_grant_types, redirect_uris, scopes, client_settings, token_settings)
values('95f5c1d7-6369-4973-b8f3-f6095cb1ab91', 'test', '2021-10-25 16:54:43', '$2a$10$zayY.GBFA4X6DRYdwb0fQuAWv7QQsf37it3DW4fRSWRL5EYjfu/eW', NULL, '测试', 'client_secret_basic', 'refresh_token,authorization_code', 'http://127.0.0.1:3000/login', 'openid', '{\"@class\":\"java.util.Collections$UnmodifiableMap\",\"settings.client.require-proof-key\":false,\"settings.client.require-authorization-consent\":false}', '{\"@class\":\"java.util.Collections$UnmodifiableMap\",\"settings.token.reuse-refresh-tokens\":false,\"settings.token.id-token-signature-algorithm\":[\"org.springframework.security.oauth2.jose.jws.SignatureAlgorithm\",\"RS256\"],\"settings.token.authorization-code-time-to-live\":[\"java.time.Duration\",300.000000000],\"settings.token.access-token-time-to-live\":[\"java.time.Duration\",7200.000000000],\"settings.token.access-token-format\":{\"@class\":\"org.springframework.security.oauth2.server.authorization.settings.OAuth2TokenFormat\",\"value\":\"self-contained\"},\"settings.token.refresh-token-time-to-live\":[\"java.time.Duration\",86400.000000000]}');
insert into user( id, name, mobile, password, disabled, locked, create_time, update_time)
values(1, '张三', '16688886666', '$2a$10$9Lymb0LDjl2b2TNH5I81Quysl0wMWy4tiqqS2/9GrNNC0KRZSaJRW', '0', '0', '2022-10-01 00:00:00', '2022-10-01 00:00:00');
insert into role( id, name, disabled, create_time)
values(1, 'ROLE_ADMIN', '0', '2022-10-01 00:00:00');
insert into user_role( user_id, role_id) values ( 1, 1);
完成code模式获取token。
1.打开浏览器输入地址,在跳转的登录窗口输入手机号16688886666密码123,获取code:
2.打开postman工具。
请求地址:http://127.0.0.1:8000/oauth2/token
请求方法:POST
请求参数:grant_type 填写 authorization_code、code填写上一步获取的code、scope填写openid、redirect_uri填写http://127.0.0.1:3000/login
认证Authorization的类型type选择Basic Auth : Username 填写test、password填写123
发送请求,就能获取token了。