README ¶
⚠️ This repository is now archived. Please use traPtitech/go-traq-oauth2 ⚠️
traq-oauth2
traq-oauth2 provides support for OAuth2 authentication in traQ
Features
- Authorization Code Flow
- Only this flow is supported in traQ.
- Proof Key for Code Exchange
- PKCE is supported in traQ.
- Few dependencies
- traq-oauth2 only depends on golang.org/x/oauth2 and standard libraries.
Installation
package main
import (
// ...
traqoauth2 "github.com/ras0q/traq-oauth2"
)
Usage
See example
Documentation ¶
Index ¶
- Variables
- func GenerateCodeChallenge(codeVerifier string, codeChallengeMethod CodeChallengeMethod) (string, error)
- func GenerateCodeVerifier() (string, error)
- func WithCodeChallenge(codeChallenge string) oauth2.AuthCodeOption
- func WithCodeChallengeMethod(codeChallengeMethod CodeChallengeMethod) oauth2.AuthCodeOption
- func WithCodeVerifier(codeVerifier string) oauth2.AuthCodeOption
- type CodeChallengeMethod
- type Config
Constants ¶
This section is empty.
Variables ¶
var ( ErrGenerateCodeverifier = errors.New("failed to generate code verifier") ErrGenerateCodechallenge = errors.New("failed to generate code challenge") ErrExchangeCode = errors.New("failed to exchange code") )
var TraQ = oauth2.Endpoint{
AuthURL: "https://q.trap.jp/api/v3/oauth2/authorize",
TokenURL: "https://q.trap.jp/api/v3/oauth2/token",
}
Traq is the OAuth2 endpoint for traQ.
Functions ¶
func GenerateCodeChallenge ¶
func GenerateCodeChallenge(codeVerifier string, codeChallengeMethod CodeChallengeMethod) (string, error)
GenerateCodeChallenge generates the code challenge from the code verifier. Ref: https://www.rfc-editor.org/rfc/rfc7636#section-4.2
func GenerateCodeVerifier ¶
GenerateCodeVerifier generates a code verifier. Ref: https://www.rfc-editor.org/rfc/rfc7636#section-4.1
func WithCodeChallenge ¶
func WithCodeChallenge(codeChallenge string) oauth2.AuthCodeOption
WithCodeChallenge sets the code_challenge parameter.
func WithCodeChallengeMethod ¶
func WithCodeChallengeMethod(codeChallengeMethod CodeChallengeMethod) oauth2.AuthCodeOption
WithCodeChallengeMethod sets the code_challenge_method parameter. The default value is "plain". If you want to use "S256", use WithCodeChallengeMethod(traqoauth2.CodeChallengeS256).
func WithCodeVerifier ¶
func WithCodeVerifier(codeVerifier string) oauth2.AuthCodeOption
WithCodeVerifier sets the code_verifier parameter. If you had use WithCodeChallenge, you also must use this.
Types ¶
type CodeChallengeMethod ¶
type CodeChallengeMethod int
CodeChallengeMethod represents the code challenge method.
const ( // CodeChallengePlain is the PKCE "plain" method. CodeChallengePlain CodeChallengeMethod = iota // CodeChallengeS256 is the PKCE "S256" method. CodeChallengeS256 )
func CodeChallengeMethodFromStr ¶ added in v0.1.0
func CodeChallengeMethodFromStr(s string) (CodeChallengeMethod, bool)
CodeChallengeMethodFromStr returns the CodeChallengeMethod from the string. If the string is empty, CodeChallengePlain is returned.
func (CodeChallengeMethod) String ¶ added in v0.1.0
func (m CodeChallengeMethod) String() string
String returns the string representation of the CodeChallengeMethod.
type Config ¶
Config is a wrapper of oauth2.Config.
func (*Config) AuthorizeWithPKCE ¶ added in v0.1.0
func (c *Config) AuthorizeWithPKCE(codeChallengeMethod CodeChallengeMethod, state string) (codeVerifier string, authURL string, err error)
AuthorizeWithPKCE returns the code verifier and the authorization URL.