authorization fix
This commit is contained in:
parent
9e9b0f6083
commit
b1a5e5a5b9
|
@ -16,15 +16,16 @@ type AuthorizationStateHandler interface {
|
||||||
func Authorize(client *Client, authorizationStateHandler AuthorizationStateHandler) error {
|
func Authorize(client *Client, authorizationStateHandler AuthorizationStateHandler) error {
|
||||||
defer authorizationStateHandler.Close()
|
defer authorizationStateHandler.Close()
|
||||||
|
|
||||||
|
var authorizationError error
|
||||||
|
|
||||||
for {
|
for {
|
||||||
state, err := client.GetAuthorizationState()
|
state, err := client.GetAuthorizationState()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = authorizationStateHandler.Handle(client, state)
|
if state.AuthorizationStateType() == TypeAuthorizationStateClosed {
|
||||||
if err != nil {
|
return authorizationError
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if state.AuthorizationStateType() == TypeAuthorizationStateReady {
|
if state.AuthorizationStateType() == TypeAuthorizationStateReady {
|
||||||
|
@ -32,6 +33,12 @@ func Authorize(client *Client, authorizationStateHandler AuthorizationStateHandl
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = authorizationStateHandler.Handle(client, state)
|
||||||
|
if err != nil {
|
||||||
|
authorizationError = err
|
||||||
|
client.Close()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,10 +107,10 @@ func (stateHandler *clientAuthorizer) Handle(client *Client, state Authorization
|
||||||
return ErrNotSupportedAuthorizationState
|
return ErrNotSupportedAuthorizationState
|
||||||
|
|
||||||
case TypeAuthorizationStateClosing:
|
case TypeAuthorizationStateClosing:
|
||||||
return ErrNotSupportedAuthorizationState
|
return nil
|
||||||
|
|
||||||
case TypeAuthorizationStateClosed:
|
case TypeAuthorizationStateClosed:
|
||||||
return ErrNotSupportedAuthorizationState
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return ErrNotSupportedAuthorizationState
|
return ErrNotSupportedAuthorizationState
|
||||||
|
|
|
@ -71,8 +71,6 @@ func NewClient(authorizationStateHandler AuthorizationStateHandler, options ...O
|
||||||
|
|
||||||
err := Authorize(client, authorizationStateHandler)
|
err := Authorize(client, authorizationStateHandler)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
client.Stop()
|
|
||||||
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue