-
Notifications
You must be signed in to change notification settings - Fork 3
/
idp.go
83 lines (68 loc) · 1.93 KB
/
idp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package hubauth
import (
"context"
"errors"
"net/url"
"time"
)
var ErrUnauthorizedUser = errors.New("hubauth: unauthorized user")
type AuthorizeCodeRequest struct {
AuthorizeUserRequest
RPState string
Params url.Values
}
const (
ResponseModeQuery = "query"
ResponseModeFragment = "fragment"
)
type AuthorizeUserRequest struct {
ClientID string
RedirectURI string
ClientState string
Nonce string
CodeChallenge string
ResponseMode string
}
type AuthorizeResponse struct {
URL string
RPState string
Interstitial bool
DisplayCode string
}
type ExchangeCodeRequest struct {
ClientID string
RedirectURI string
Audience string
Code string
CodeVerifier string
}
type AccessToken struct {
RefreshToken string `json:"refresh_token"`
AccessToken string `json:"access_token"`
TokenType string `json:"token_type"`
ExpiresIn int `json:"expires_in"`
Nonce string `json:"nonce,omitempty"`
Audience string `json:"audience,omitempty"`
RefreshTokenExpiresIn int `json:"refresh_token_expires_in"`
RefreshTokenIssueTime time.Time `json:"refresh_token_issue_time"`
// used by HTTP layer to set Access-Control-Allow-Origin
RedirectURI string `json:"-"`
}
type RefreshTokenRequest struct {
ClientID string
Audience string
RefreshToken string
}
type ListAudiencesRequest struct {
RefreshToken string
}
type ListAudiencesResponse struct {
Audiences []*Audience `json:"audiences"`
}
type IdPService interface {
AuthorizeUserRedirect(ctx context.Context, req *AuthorizeUserRequest) (*AuthorizeResponse, error)
AuthorizeCodeRedirect(ctx context.Context, req *AuthorizeCodeRequest) (*AuthorizeResponse, error)
ExchangeCode(ctx context.Context, req *ExchangeCodeRequest) (*AccessToken, error)
RefreshToken(ctx context.Context, req *RefreshTokenRequest) (*AccessToken, error)
ListAudiences(ctx context.Context, req *ListAudiencesRequest) (*ListAudiencesResponse, error)
}