From 148a56078e0eee3d55d29709d2f753e8efbbb2fd Mon Sep 17 00:00:00 2001 From: stijndcl Date: Mon, 17 Jul 2023 09:04:01 +0200 Subject: [PATCH 1/2] Use subdomain in authenticator --- .idea/.gitignore | 8 ++++++++ .idea/modules.xml | 8 ++++++++ .idea/onelogin-go-sdk.iml | 9 +++++++++ .idea/vcs.xml | 6 ++++++ pkg/onelogin/api/client.go | 2 +- pkg/onelogin/authentication/authenticator.go | 11 ++++++----- 6 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/modules.xml create mode 100644 .idea/onelogin-go-sdk.iml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..59e719d --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/onelogin-go-sdk.iml b/.idea/onelogin-go-sdk.iml new file mode 100644 index 0000000..5e764c4 --- /dev/null +++ b/.idea/onelogin-go-sdk.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file 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 { From 725cad106e2e7b248cdeaa3243d055e117bdaddf Mon Sep 17 00:00:00 2001 From: stijndcl Date: Mon, 17 Jul 2023 09:07:54 +0200 Subject: [PATCH 2/2] Update docs & remove idea folder --- .idea/.gitignore | 8 -------- .idea/modules.xml | 8 -------- .idea/onelogin-go-sdk.iml | 9 --------- .idea/vcs.xml | 6 ------ docs/authentication.md | 8 ++++---- 5 files changed, 4 insertions(+), 35 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/modules.xml delete mode 100644 .idea/onelogin-go-sdk.iml delete mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 13566b8..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 59e719d..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/onelogin-go-sdk.iml b/.idea/onelogin-go-sdk.iml deleted file mode 100644 index 5e764c4..0000000 --- a/.idea/onelogin-go-sdk.iml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file 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 } ```