traqoauth2

package module
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2023 License: MIT Imports: 7 Imported by: 3

README

⚠️ This repository is now archived. Please use traPtitech/go-traq-oauth2 ⚠️

traq-oauth2

Go Reference

traq-oauth2 provides support for OAuth2 authentication in traQ

Features

Installation

package main

import (
	// ...
	traqoauth2 "github.com/ras0q/traq-oauth2"
)

Usage

See example

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrGenerateCodeverifier  = errors.New("failed to generate code verifier")
	ErrGenerateCodechallenge = errors.New("failed to generate code challenge")
	ErrExchangeCode          = errors.New("failed to exchange code")
)
View Source
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

func GenerateCodeVerifier() (string, error)

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

type Config struct {
	*oauth2.Config
}

Config is a wrapper of oauth2.Config.

func NewConfig

func NewConfig(clientID string, redirectURL string, opts ...func(*Config)) *Config

NewConfig returns a new oauth2.Config for traQ.

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.

func (*Config) CallbackWithPKCE added in v0.1.0

func (c *Config) CallbackWithPKCE(ctx context.Context, codeVerifier string, code string) (*oauth2.Token, error)

CallbackWithPKCE exchanges the code for a token.

Directories

Path Synopsis
example
cli

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL