{"id":15294958,"url":"https://github.com/bartmika/osin-example","last_synced_at":"2025-08-23T00:24:48.632Z","repository":{"id":74312830,"uuid":"443618231","full_name":"bartmika/osin-example","owner":"bartmika","description":"Example of a identity provider powered by OAuth 2.0 in Golang","archived":false,"fork":false,"pushed_at":"2022-01-05T06:06:36.000Z","size":126,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-29T22:29:52.966Z","etag":null,"topics":["golang-examples","oauth2","oauth2-server"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bartmika.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-01T20:29:01.000Z","updated_at":"2022-01-05T06:06:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"df9de6a9-4ec7-43e7-9bf8-0985642688af","html_url":"https://github.com/bartmika/osin-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bartmika%2Fosin-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bartmika%2Fosin-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bartmika%2Fosin-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bartmika%2Fosin-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bartmika","download_url":"https://codeload.github.com/bartmika/osin-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245320001,"owners_count":20596085,"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":["golang-examples","oauth2","oauth2-server"],"created_at":"2024-09-30T17:08:07.718Z","updated_at":"2025-03-24T17:43:45.004Z","avatar_url":"https://github.com/bartmika.png","language":"Go","readme":"# OSIN Example\nThe purpose of this repository is to provide Golang example code of an identity provider using oAuth 2.0 to grant access to users and [third-party developers](https://github.com/bartmika/osin-thirdparty-example). This code uses the [`openshift/osin`](https://github.com/openshift/osin) Golang oAuth 2.0 library.\n\n## Setup\n\n1. Clone the project.\n\n2. Install the dependencies\n\n    ```\n    go get ./...\n    ```\n\n3. Please create a default client which you can use to a frontend.\n\n    ```\n    go run main.go add_client --client_id=frontend \\\n                              --client_secret=pleasechangethisnow \\\n                              --redirect_uri=http://127.0.0.1:8002/appauth/code\n    ```\n\n3. Setup the database.\n\n4. Run the following environment variables in your terminal:\n\n    ```bash\n    export OSIN_DB_HOST=localhost\n    export OSIN_DB_PORT=5432\n    export OSIN_DB_USER=golang\n    export OSIN_DB_PASSWORD=123password\n    export OSIN_DB_NAME=osinexample_db\n    export OSIN_APP_ADDRESS=http://127.0.0.1:8000\n    export OSIN_APP_SECRET_KEY=pass-secret-1234566-please-change-me\n    export OSIN_APP_FRONTEND_CLIENT_ID=frontend\n    export OSIN_APP_FRONTEND_CLIENT_SECRET=pleasechangethisnow\n    export OSIN_APP_FRONTEND_RETURN_URL=http://127.0.0.1:8001/appauth/code\n    ```\n\n5. Run the server.\n\n    ```bash\n    go run main.go serve\n    ```\n\n6. You are ready to use your server.\n\n## Documentation\n\n### Unprotected Resources\n\n#### User Registration\n\nRegister an identity with our system.\n\n```bash\ngo run main.go register -b=Bart -c=Mika -d=demo@demo.com -e=123password -f=en\n```\n\n#### User Login\n\nSimple login, run and then copy+paste the result export to the terminal\n\n```bash\ngo run main.go login --email=demo@demo.com --password=123password\n```\n\n#### User Token Refresh\n\nGet new refresh API\n\n```bash\ngo run main.go refresh_token --refresh_token=xxx --grant_type=refresh_token\n```\n\n### oAuth 2.0\n\n#### Password Grant\n\nHere is how you do password based grant\n\n```bash\ngo run main.go osin_password --email=demo@demo.com \\\n                             --password=123password \\\n                             --client_id=frontend \\\n                             --client_secret=pleasechangethisnow \\\n                             --redirect_uri=http://127.0.0.1:8001/appauth/code \\\n                             --authorize_uri=http://localhost:8000/authorize \\\n                             --token_url=http://localhost:8000/token\n```\n\n#### Client Credentials Grant\n\nGet our token from the client credentials.\n\n```\ngo run main.go osin_client_credential --client_id=frontend \\\n                                      --client_secret=pleasechangethisnow \\\n                                      --redirect_uri=http://127.0.0.1:8001/appauth/code \\\n                                      --authorize_uri=http://localhost:8000/authorize \\\n                                      --token_url=http://localhost:8000/authorize\n```\n\n### Refresh Token\n\nLet's refresh our access token with our refresh token.\n\n```\ngo run main.go osin_refresh_token --client_id=frontend \\\n                                  --client_secret=pleasechangethisnow \\\n                                  --redirect_uri=http://127.0.0.1:8001/appauth/code \\\n                                  --authorize_uri=http://localhost:8000/authorize \\\n                                  --token_url=http://localhost:8000/authorize\n```\n\n### Protect Resources\n\n#### Get Tenant\n\nCheck we are able to access our protected resource\n\n```bash\ngo run main.go tenant_retrieve --id=1\n```\n\n\n## License\nMade with ❤️ by [Bartlomiej Mika](https://bartlomiejmika.com).   \nThe project is licensed under the [Unlicense](LICENSE).\n\nThird party libraries and resources:\n\n* [github.com/openshift/osin](https://github.com/openshift/osin) (BSD-3-Clause License) is used for oAuth 2.0 server implementation.\n* [github.com/ShaleApps/osinredis](https://github.com/ShaleApps/osinredis) (MIT) is used for the oAuth 2.0 server session storage handling.\n* [go-oauth2/oauth2](https://github.com/go-oauth2/oauth2) (MIT) was not used but was a valuable learning resource.\n* [golang.org/x/oauth2](https://pkg.go.dev/golang.org/x/oauth2) (BSD-3-Clause License) is used for client side oAuth 2.0 library.\n* [github.com/google/uuid](https://github.com/google/uuid) (BSD-3-Clause License) is used for generating UUID values.\n* [github.com/rs/cors](https://github.com/rs/cors) (MIT) is used for dealing with CORS headers for every request made to this API server.\n* [github.com/spf13/cobra](https://github.com/spf13/cobra) (Apache-2.0 License) is used to structure this application using a CLI.\n* [github.com/go-redis/redis](https://github.com/go-redis/redis) (BSD-2-Clause License) is used for `redis` handling.\n* [golang.org/x/crypto/bcrypt](https://golang.org/x/crypto/bcrypt) (BSD-3-Clause License) is used for password hashing.\n* [github.com/lib/pq](https://github.com/lib/pq) (OTHER) is used for `postgres` handling.\n* [gopkg.in/guregu/null.v4](https://gopkg.in/guregu/null.v4) (BSD-2-Clause License) is used for null fields in marshal/unmarshal operations.\n* [rfc6749 - The OAuth 2.0 Authorization Framework](https://datatracker.ietf.org/doc/html/rfc6749) used as specs.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbartmika%2Fosin-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbartmika%2Fosin-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbartmika%2Fosin-example/lists"}