{"id":15627651,"url":"https://github.com/v5tech/oltu-oauth2-example","last_synced_at":"2025-04-05T22:11:09.100Z","repository":{"id":32769207,"uuid":"36360721","full_name":"v5tech/oltu-oauth2-example","owner":"v5tech","description":"使用Apache Oltu 搭建Oauth2 Server及Client开放授权","archived":false,"fork":false,"pushed_at":"2022-12-16T02:49:03.000Z","size":3262,"stargazers_count":344,"open_issues_count":13,"forks_count":178,"subscribers_count":42,"default_branch":"master","last_synced_at":"2025-03-29T21:08:57.956Z","etag":null,"topics":["oauth2","oltu","oltu-oauth2"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/v5tech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-27T10:48:54.000Z","updated_at":"2025-02-14T08:01:52.000Z","dependencies_parsed_at":"2023-01-14T22:10:31.138Z","dependency_job_id":null,"html_url":"https://github.com/v5tech/oltu-oauth2-example","commit_stats":null,"previous_names":["v5tech/oltu-oauth2-example"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/v5tech%2Foltu-oauth2-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/v5tech%2Foltu-oauth2-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/v5tech%2Foltu-oauth2-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/v5tech%2Foltu-oauth2-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/v5tech","download_url":"https://codeload.github.com/v5tech/oltu-oauth2-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247406111,"owners_count":20933806,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["oauth2","oltu","oltu-oauth2"],"created_at":"2024-10-03T10:18:30.058Z","updated_at":"2025-04-05T22:11:09.084Z","avatar_url":"https://github.com/v5tech.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Apache Oltu OAuth2 Server + Client\n\n\n使用Apache Oltu 搭建Oauth2 Server及Client开放授权\n\nOAuth应用接入授权演示\n\n![](oauth2.gif)\n\n纯代码方式接入OAuth演示\n\n![](oauth2-client.gif)\n\n\nOauth2 Server端执行流程\n\n打包运行\n\n```\nmvn jetty:run\n或\nmvn tomcat7:run\n```\n\n### 1. 先注册应用\n\nhttp://localhost:8080/zetark-oauth2-server/client\n\n会生成client_id和client_secret这两个以后会用到\n\n```\nclient_id               c1ebe466-1cdc-4bd3-ab69-77c3561b9dee    应用id\nclient_secret           d8346ea2-6017-43ed-ad68-19c0f971738b    应用secret\n```\n\n### 2. 请求授权码\n\nhttp://localhost:8080/zetark-oauth2-server/authorize?client_id=c1ebe466-1cdc-4bd3-ab69-77c3561b9dee\u0026response_type=code\u0026redirect_uri=http://notes.coding.me\n\n参数说明\n\n```\nclient_id               应用id\nresponse_type           返回授权码的标识\nredirect_uri            回调地址\n```\n\n上面的网站会打开oauth server的用户登录页面。用户输入正确的用户名和密码以POST方式提交后会重定向到用户所填的回调地址并在地址后携带授权码.\n\n请求成功后会返回如下的页面:\n\nhttp://notes.coding.me/?code=63910432da9186b22b1ad888d55ae8ae\n\n这里code=63910432da9186b22b1ad888d55ae8ae即授权码\n\n### 3. 换取accessToken (POST操作)\n\n首先GET方式请求 http://localhost:8080/zetark-oauth2-server/access 会打开一个表单在该表单中填入必填项，具体表单参数详见说明部分\n\n表单将会以POST方式提交到 http://localhost:8080/zetark-oauth2-server/accessToken ,最终返回accessToken\n\n需要以POST方式提交以下参数换取accessToken\n\n```\nclient_id       c1ebe466-1cdc-4bd3-ab69-77c3561b9dee            应用id\nclient_secret   d8346ea2-6017-43ed-ad68-19c0f971738b            应用secret\ngrant_type      authorization_code                              用于传递授权码的参数名authorization_code\ncode            63910432da9186b22b1ad888d55ae8ae                用户登录授权后的授权码\nredirect_uri    http://notes.coding.me                          回调地址\n```\n\n最终返回如下数据\n\n```\n{\"expires_in\":3600,\"access_token\":\"223ae05dfbb0794396fb60a0960c197e\"}\n```\n\n### 4. 使用accessToken测试开放数据服务\n\nhttp://localhost:8080/zetark-oauth2-server/v1/openapi/userInfo?access_token=223ae05dfbb0794396fb60a0960c197e\n\n测试ok的话返回用户名信息,access_token=223ae05dfbb0794396fb60a0960c197e为上一步获取的access_token\n\n注：其中的参数名不要随意更改，固定写法。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fv5tech%2Foltu-oauth2-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fv5tech%2Foltu-oauth2-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fv5tech%2Foltu-oauth2-example/lists"}