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

feat( add OAuth2 support ) #1533

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

HarbingerNight
Copy link

@HarbingerNight HarbingerNight commented May 31, 2024

Adds support for Discord's OAuth2 token api.

  • added missing basic OAuth2 endpoints to endpoints.go
  • added util functions to create a 'Basic' token from client id and secret to use in OAuth2 requests
  • added util functions to prefix 'Bearer' and 'Bot' tokens to util.go for consistency
  • added methods to check token type on Session in structs.go placed errors for them with other
  • errors in restapi.go
  • modified RequestWithBucketID in restapi.go to check if data is of type url.Values and if so format and send data as content-type x-form-urlencoded to address Discord's pedantic adherence to OAuth2 spec
  • moved current oauth2.go and oauth2_test.go to applications.go and applications_test.go in keeping with their main focus
  • added oauth2.go with basic OAuth2 types and methods
  • added ability to preform OAuth2 operations to Session when Session has been created with a 'Basic' token using client id and secret in oauth2.go
  • added ability to retrieve the current token's authorization info for Session's created with 'Bearer' or 'Bot' tokens
  • added godoc comments for above
  • added demo oauth2 http/s server in examples

closes #1534

  moved oauth2.go and oauth2_test.go to applications.go and
    applications_test.go
  added basic OAuth2 endpoints to endpoints.go
  added util functions for creating 'Basic' token from client id
    and secret to util.go
  added util functions for prefixing 'Bearer' and 'Bot' tokens to
    util.go
  added methods to check token type on Sessions in structs.go
  added wrong token type errors to restapi.go
  changed RequestWithBucketID to use x-form-urlencoded encoding
    when given a url.Values data object to deal with discord's
    pendantic OAuth2 spec adherence
  created oauth2.go with basic OAuth2 types
  added ability to preform OAuth2 operation with a Session
    created from a 'Basic' token using client id and secret
  added ability to get OAuth2 authorization information for
    Session's created with 'Bearer' and 'Bot' tokens
  added godoc comments for above
  created a OAuth2 demo server in examples
@HarbingerNight
Copy link
Author

what is the likelyhood of this or something similar in the next version?

if err = s.checkBasicSession(); err != nil { return }
body, err := s.RequestWithBucketID( "POST", EndpointOAuth2Token, data, EndpointOAuth2Token, options... )
if err == nil {
err = unmarshal( body, &st )

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unhandled error, I caught a panic here)

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

Successfully merging this pull request may close these issues.

OAuth2 support missing
2 participants