Skip to content

Commit

Permalink
Fix authentication (#73)
Browse files Browse the repository at this point in the history
* Use subdomain in authenticator

* Update docs & remove idea folder
  • Loading branch information
stijndcl committed Jul 17, 2023
1 parent 130b440 commit cf20670
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
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

0 comments on commit cf20670

Please sign in to comment.