(ctx context.Context, args map[string]string)
| 71 | } |
| 72 | |
| 73 | func (d *Driver) ThirdLogin(ctx context.Context, args map[string]string) (string, error) { |
| 74 | code, ok := args["code"] |
| 75 | if !ok { |
| 76 | return "", fmt.Errorf("missing code parameter") |
| 77 | } |
| 78 | clientId, ok := args["client_id"] |
| 79 | if !ok { |
| 80 | return "", fmt.Errorf("missing client_id parameter") |
| 81 | } |
| 82 | clientSecret, ok := args["client_secret"] |
| 83 | if !ok { |
| 84 | return "", fmt.Errorf("missing client_secret parameter") |
| 85 | } |
| 86 | redirectUri, ok := args["redirect_uri"] |
| 87 | if !ok { |
| 88 | return "", fmt.Errorf("missing redirect_uri parameter") |
| 89 | } |
| 90 | u, err := url.Parse(redirectUri) |
| 91 | if err != nil { |
| 92 | return "", fmt.Errorf("invalid redirect_uri parameter") |
| 93 | } |
| 94 | query := u.Query() |
| 95 | query.Del("code") |
| 96 | redirectUri = fmt.Sprintf("%s://%s%s", u.Scheme, u.Host, u.Path) |
| 97 | if len(query) > 0 { |
| 98 | redirectUri = fmt.Sprintf("%s?%s", redirectUri, query.Encode()) |
| 99 | } |
| 100 | tokenResp, err := getUserToken(code, redirectUri, clientId, clientSecret) |
| 101 | if err != nil { |
| 102 | return "", err |
| 103 | } |
| 104 | userInfoResp, err := getUserInfo(tokenResp.TokenType, tokenResp.AccessToken) |
| 105 | if err != nil { |
| 106 | return "", err |
| 107 | } |
| 108 | userId := userInfoResp.Data.UnionId |
| 109 | username := userInfoResp.Data.Name |
| 110 | email := userInfoResp.Data.Email |
| 111 | mobile := userInfoResp.Data.Mobile |
| 112 | info, err := d.accountService.GetIdentifier(ctx, name, userId) |
| 113 | if err != nil { |
| 114 | if !errors.Is(err, gorm.ErrRecordNotFound) { |
| 115 | return "", err |
| 116 | } |
| 117 | uId := uuid.NewString() |
| 118 | |
| 119 | err = d.accountService.Save(ctx, name, uId, userId, utils.Md5(fmt.Sprintf("%s%s", uId, userId))) |
| 120 | if err != nil { |
| 121 | return "", err |
| 122 | } |
| 123 | _, err = d.userService.Create(ctx, uId, username, email, mobile, name) |
| 124 | if err != nil { |
| 125 | return "", err |
| 126 | } |
| 127 | r, err := d.roleService.GetDefaultRole(ctx, role.SystemTarget()) |
| 128 | if err != nil { |
| 129 | return "", err |
| 130 | } |
nothing calls this directly
no test coverage detected