Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/realtristan/disgoauth
Easy-to-use Discord OAuth2.0 Implementation for Go
https://github.com/realtristan/disgoauth
discord discord-api discord-oauth golang oauth oauth2
Last synced: about 5 hours ago
JSON representation
Easy-to-use Discord OAuth2.0 Implementation for Go
- Host: GitHub
- URL: https://github.com/realtristan/disgoauth
- Owner: realTristan
- License: mit
- Created: 2022-09-02T00:46:51.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2022-12-12T11:55:41.000Z (almost 2 years ago)
- Last Synced: 2024-06-22T03:14:49.281Z (5 months ago)
- Topics: discord, discord-api, discord-oauth, golang, oauth, oauth2
- Language: Go
- Homepage: https://realtristan.github.io/disgoauth/
- Size: 54.7 KB
- Stars: 10
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DisGOAuth ![Stars](https://img.shields.io/github/stars/realTristan/disgoauth?color=brightgreen) ![Watchers](https://img.shields.io/github/watchers/realTristan/disgoauth?label=Watchers)
![banner](https://user-images.githubusercontent.com/75189508/188035581-008c64d0-d59a-4a95-9e75-55cb3d8f4e79.png)Discord OAuth2.0 Implementation for Go
# Why DisGOAuth?
- DisGOAuth is a light-weight, fast and easy-to-use module that makes using Discord's OAuth2.0 much easier.
- DisGOAuth uses solely native golang packages which makes it fast and secure.
- DisGOAuth provides functions for all of the oauth endpoints# Installation
`go get -u github.com/realTristan/disgoauth`# Quick Usage
```gopackage main
// Import Packages
import (
"fmt"
"net/http"// Import DisGOAuth
disgoauth "github.com/realTristan/disgoauth"
)// Main function
func main() {
// Establish a new discord client
var dc *disgoauth.Client = disgoauth.Init(&disgoauth.Client{
ClientID: "CLIENT ID",
ClientSecret: "CLIENT SECRET",
RedirectURI: "http://localhost:8000/redirect",
Scopes: []string{disgoauth.ScopeIdentify},
})// Home Page Handler
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
// Send the user to the discord authentication
// website. This is where they authorize access.
//
// The third parameter in the RedirectHandler is the
// state. If you're storing a state, PLEASE base64 encode
// it beforehand!
dc.RedirectHandler(w, r, "") // w: http.ResponseWriter, r: *http.Request, state: string
})// The OAuth URL Redirect Uri
http.HandleFunc("/redirect", func(w http.ResponseWriter, r *http.Request) {
// Define Variables
var (
// Get the code from the redirect parameters (&code=...)
codeFromURLParamaters = r.URL.Query()["code"][0]// Get the access token using the above codeFromURLParamaters
accessToken, _ = dc.GetOnlyAccessToken(codeFromURLParamaters)// Get the authorized user's data using the above accessToken
userData, _ = disgoauth.GetUserData(accessToken)
)
// Print the user data map
fmt.Println(userData)
})// Listen and Serve to the incoming http requests
http.ListenAndServe(":8000", nil)
}
```# License
MIT LicenseCopyright (c) 2022 Tristan Simpson
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.