Skip to content

Commit

Permalink
feat: support co-authn
Browse files Browse the repository at this point in the history
  • Loading branch information
zensh committed Sep 20, 2023
1 parent adfff3c commit 7671f52
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/api/authn.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,25 @@ func (a *AuthN) Callback(ctx *gear.Context) error {
}
input.DeviceDesc = strings.Join(desc, ", ")

switch idp {
case "wechat":
if coIdp, ok := a.providers["wechat_h5"]; ok {
input.CoAuthN = &bll.AuthNPK{
Idp: "wechat_h5",
Aud: coIdp.ClientID,
Sub: input.Sub,
}
}
case "wechat_h5":
if coIdp, ok := a.providers["wechat"]; ok {
input.CoAuthN = &bll.AuthNPK{
Idp: "wechat",
Aud: coIdp.ClientID,
Sub: input.Sub,
}
}
}

res, err := a.blls.AuthN.LoginOrNew(ctx, input)
if err != nil {
next := a.authURL.GenNextUrl(nextURL, 500, xid)
Expand Down
7 changes: 7 additions & 0 deletions src/bll/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ type UserInfo struct {
Status int8 `json:"status" cbor:"status"`
}

type AuthNPK struct {
Idp string `json:"idp" cbor:"idp"`
Aud string `json:"aud" cbor:"aud"`
Sub string `json:"sub" cbor:"sub"`
}

type AuthNInput struct {
Idp string `json:"idp" cbor:"idp"`
Aud string `json:"aud" cbor:"aud"`
Expand All @@ -64,6 +70,7 @@ type AuthNInput struct {
DeviceDesc string `json:"device_desc" cbor:"device_desc"`
Payload []byte `json:"payload" cbor:"payload"`
User UserInfo `json:"user" cbor:"user"`
CoAuthN *AuthNPK `json:"co_authn,omitempty" cbor:"co_authn,omitempty"`
}

type AuthNSessionOutput struct {
Expand Down

0 comments on commit 7671f52

Please sign in to comment.