diff --git a/docs/authentication.md b/docs/authentication.md index 0f8acfe..bae648e 100644 --- a/docs/authentication.md +++ b/docs/authentication.md @@ -14,11 +14,11 @@ type Authenticator struct { ## NewAuthenticator Function -The `NewAuthenticator` function is used to create a new `Authenticator` instance. It does not require any arguments and it initializes a new Authenticator with an empty `accessToken`. +The `NewAuthenticator` function is used to create a new `Authenticator` instance. It requires the subdomain as an argument, and it initializes a new Authenticator with an empty `accessToken`. ```go -func NewAuthenticator() *Authenticator { - return &Authenticator{} +func NewAuthenticator(subdomain string) *Authenticator { + return &Authenticator{subdomain: subdomain} } ``` @@ -37,7 +37,7 @@ func (a *Authenticator) GenerateToken() error { The `RevokeToken` function is used to revoke an existing access token. It reads the `ONELOGIN_CLIENT_ID` and `ONELOGIN_CLIENT_SECRET` environment variables, creates a revocation request, sends it, and handles the response. If the revocation is successful, a confirmation message is printed. ```go -func (a *Authenticator) RevokeToken(token, domain *string) error { +func (a *Authenticator) RevokeToken(token *string) error { // implementation details } ``` diff --git a/pkg/onelogin/api/client.go b/pkg/onelogin/api/client.go index c719322..8ae3424 100644 --- a/pkg/onelogin/api/client.go +++ b/pkg/onelogin/api/client.go @@ -38,7 +38,7 @@ type Authenticator interface { func NewClient() (*Client, error) { subdomain := os.Getenv("ONELOGIN_SUBDOMAIN") old := fmt.Sprintf("https://%s.onelogin.com", subdomain) - authenticator := authentication.NewAuthenticator() + authenticator := authentication.NewAuthenticator(subdomain) err := authenticator.GenerateToken() if err != nil { return nil, err diff --git a/pkg/onelogin/authentication/authenticator.go b/pkg/onelogin/authentication/authenticator.go index 2dfde0d..a735475 100644 --- a/pkg/onelogin/authentication/authenticator.go +++ b/pkg/onelogin/authentication/authenticator.go @@ -19,10 +19,11 @@ const ( type Authenticator struct { accessToken string + subdomain string } -func NewAuthenticator() *Authenticator { - return &Authenticator{} +func NewAuthenticator(subdomain string) *Authenticator { + return &Authenticator{subdomain: subdomain} } func (a *Authenticator) GenerateToken() error { @@ -38,7 +39,7 @@ func (a *Authenticator) GenerateToken() error { } // Construct the authentication URL - authURL := fmt.Sprintf("https://api.onelogin.com%s", TkPath) + authURL := fmt.Sprintf("https://%s.onelogin.com%s", a.subdomain, TkPath) // Create authentication request payload data := map[string]string{ @@ -92,7 +93,7 @@ func (a *Authenticator) GenerateToken() error { return nil } -func (a *Authenticator) RevokeToken(token, domain *string) error { +func (a *Authenticator) RevokeToken(token *string) error { // Read environment variables clientID := os.Getenv("ONELOGIN_CLIENT_ID") clientSecret := os.Getenv("ONELOGIN_CLIENT_SECRET") @@ -103,7 +104,7 @@ func (a *Authenticator) RevokeToken(token, domain *string) error { } // Construct the revoke URL - revokeURL := fmt.Sprintf("api.onelogin.com%s", RevokePath) + revokeURL := fmt.Sprintf("%s.onelogin.com%s", a.subdomain, RevokePath) // Create revoke request payload data := struct {