Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix authentication #73

Merged
merged 2 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
```

Expand All @@ -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
}
```
Expand Down
2 changes: 1 addition & 1 deletion pkg/onelogin/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions pkg/onelogin/authentication/authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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{
Expand Down Expand Up @@ -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")
Expand All @@ -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 {
Expand Down
Loading