forked from Silverfish/proton-bridge
Remove unused scope methods
This commit is contained in:
committed by
Michal Horejsek
parent
f73aeec97f
commit
2e439e17cf
@ -108,7 +108,6 @@ type AuthReq struct {
|
||||
type Auth struct {
|
||||
accessToken string // Read from AuthRes.
|
||||
ExpiresIn int
|
||||
Scope string
|
||||
uid string // Read from AuthRes.
|
||||
RefreshToken string
|
||||
EventID string
|
||||
@ -174,20 +173,8 @@ type Auth2FAReq struct {
|
||||
// U2F U2FRequest
|
||||
}
|
||||
|
||||
type Auth2FA struct {
|
||||
Scope string
|
||||
}
|
||||
|
||||
type Auth2FARes struct {
|
||||
Res
|
||||
|
||||
Scope string
|
||||
}
|
||||
|
||||
func (res *Auth2FARes) getAuth2FA() *Auth2FA {
|
||||
return &Auth2FA{
|
||||
Scope: res.Scope,
|
||||
}
|
||||
}
|
||||
|
||||
type AuthRefreshReq struct {
|
||||
@ -326,33 +313,33 @@ func (c *client) Auth(username, password string, info *AuthInfo) (auth *Auth, er
|
||||
|
||||
// Auth2FA will authenticate a user into full scope.
|
||||
// `Auth` struct contains method `HasTwoFactor` deciding whether this has to be done.
|
||||
func (c *client) Auth2FA(twoFactorCode string, auth *Auth) (*Auth2FA, error) {
|
||||
func (c *client) Auth2FA(twoFactorCode string, auth *Auth) error {
|
||||
auth2FAReq := &Auth2FAReq{
|
||||
TwoFactorCode: twoFactorCode,
|
||||
}
|
||||
|
||||
req, err := c.NewJSONRequest("POST", "/auth/2fa", auth2FAReq)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
|
||||
var auth2FARes Auth2FARes
|
||||
if err := c.DoJSON(req, &auth2FARes); err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
|
||||
if err := auth2FARes.Err(); err != nil {
|
||||
switch auth2FARes.StatusCode {
|
||||
case http.StatusUnauthorized:
|
||||
return nil, ErrBad2FACode
|
||||
return ErrBad2FACode
|
||||
case http.StatusUnprocessableEntity:
|
||||
return nil, ErrBad2FACodeTryAgain
|
||||
return ErrBad2FACodeTryAgain
|
||||
default:
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return auth2FARes.getAuth2FA(), nil
|
||||
return nil
|
||||
}
|
||||
|
||||
// AuthRefresh will refresh an expired access token.
|
||||
|
||||
@ -64,16 +64,11 @@ var testAuth = &Auth{
|
||||
EventID: "NcKPtU5eMNPMrDkIMbEJrgMtC9yQ7Xc5ZBT-tB3UtV1rZ324RWfCIdBI758q0UnsfywS8CkNenIQlWLIX_dUng==",
|
||||
ExpiresIn: 86400,
|
||||
RefreshToken: "feb3159ac63fb05119bcf4480d939278aa746926",
|
||||
Scope: "full mail payments reset keys",
|
||||
|
||||
accessToken: testAccessToken,
|
||||
uid: testUID,
|
||||
}
|
||||
|
||||
var testAuth2FA = &Auth2FA{
|
||||
Scope: "full mail payments reset keys",
|
||||
}
|
||||
|
||||
var testAuthRefreshReq = AuthRefreshReq{
|
||||
ResponseType: "token",
|
||||
GrantType: "refresh_token",
|
||||
@ -160,10 +155,8 @@ func TestClient_Auth2FA(t *testing.T) {
|
||||
|
||||
c.uid = testUID
|
||||
c.accessToken = testAccessToken
|
||||
auth2FA, err := c.Auth2FA(testAuth2FAReq.TwoFactorCode, testAuth)
|
||||
err := c.Auth2FA(testAuth2FAReq.TwoFactorCode, testAuth)
|
||||
Ok(t, err)
|
||||
|
||||
Equals(t, testAuth2FA, auth2FA)
|
||||
}
|
||||
|
||||
func TestClient_Auth2FA_Fail(t *testing.T) {
|
||||
@ -182,7 +175,7 @@ func TestClient_Auth2FA_Fail(t *testing.T) {
|
||||
|
||||
c.uid = testUID
|
||||
c.accessToken = testAccessToken
|
||||
_, err := c.Auth2FA(testAuth2FAReq.TwoFactorCode, testAuth)
|
||||
err := c.Auth2FA(testAuth2FAReq.TwoFactorCode, testAuth)
|
||||
Equals(t, ErrBad2FACode, err)
|
||||
}
|
||||
|
||||
@ -202,7 +195,7 @@ func TestClient_Auth2FA_Retry(t *testing.T) {
|
||||
|
||||
c.uid = testUID
|
||||
c.accessToken = testAccessToken
|
||||
_, err := c.Auth2FA(testAuth2FAReq.TwoFactorCode, testAuth)
|
||||
err := c.Auth2FA(testAuth2FAReq.TwoFactorCode, testAuth)
|
||||
Equals(t, ErrBad2FACodeTryAgain, err)
|
||||
}
|
||||
|
||||
|
||||
@ -28,7 +28,7 @@ type Client interface {
|
||||
Auth(username, password string, info *AuthInfo) (*Auth, error)
|
||||
AuthInfo(username string) (*AuthInfo, error)
|
||||
AuthRefresh(token string) (*Auth, error)
|
||||
Auth2FA(twoFactorCode string, auth *Auth) (*Auth2FA, error)
|
||||
Auth2FA(twoFactorCode string, auth *Auth) error
|
||||
AuthSalt() (salt string, err error)
|
||||
Logout()
|
||||
DeleteAuth() error
|
||||
|
||||
@ -65,12 +65,11 @@ func (mr *MockClientMockRecorder) Auth(arg0, arg1, arg2 interface{}) *gomock.Cal
|
||||
}
|
||||
|
||||
// Auth2FA mocks base method
|
||||
func (m *MockClient) Auth2FA(arg0 string, arg1 *pmapi.Auth) (*pmapi.Auth2FA, error) {
|
||||
func (m *MockClient) Auth2FA(arg0 string, arg1 *pmapi.Auth) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Auth2FA", arg0, arg1)
|
||||
ret0, _ := ret[0].(*pmapi.Auth2FA)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Auth2FA indicates an expected call of Auth2FA
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
{
|
||||
"Code": 1000,
|
||||
"Scope": "full mail payments reset keys"
|
||||
"Scopes": ["full", "mail", "payments", "reset", "keys"]
|
||||
}
|
||||
@ -3,7 +3,7 @@
|
||||
"AccessToken": "de0423049b44243afeec7d9c1d99be7b46da1e8a",
|
||||
"ExpiresIn": 86400,
|
||||
"TokenType": "Bearer",
|
||||
"Scope": "full mail payments reset keys",
|
||||
"Scopes": ["full", "mail", "payments", "reset", "keys"],
|
||||
"UID": "729ad6012421d67ad26950dc898bebe3a6e3caa2",
|
||||
"RefreshToken": "a49b98256745bb497bec20e9b55f5de16f01fb52",
|
||||
"EventID": "NcKPtU5eMNPMrDkIMbEJrgMtC9yQ7Xc5ZBT-tB3UtV1rZ324RWfCIdBI758q0UnsfywS8CkNenIQlWLIX_dUng==",
|
||||
|
||||
@ -5,6 +5,6 @@
|
||||
"TokenType": "Bearer",
|
||||
"Uid": "729ad6012421d67ad26950dc898bebe3a6e3caa2",
|
||||
"UID": "729ad6012421d67ad26950dc898bebe3a6e3caa2",
|
||||
"Scope": "full mail payments reset keys",
|
||||
"Scopes": ["full", "mail", "payments", "reset", "keys"],
|
||||
"RefreshToken": "b894b4c4f20003f12d486900d8b88c7d68e67235"
|
||||
}
|
||||
|
||||
@ -3,6 +3,6 @@
|
||||
"AccessToken": "de0423049b44243afeec7d9c1d99be7b46da1e8a",
|
||||
"ExpiresIn": 360000,
|
||||
"TokenType": "Bearer",
|
||||
"Scope": "full mail payments reset keys",
|
||||
"Scopes": ["full", "mail", "payments", "reset", "keys"],
|
||||
"RefreshToken": "b894b4c4f20003f12d486900d8b88c7d68e67235"
|
||||
}
|
||||
Reference in New Issue
Block a user