Skip to content

Commit 14adaec

Browse files
authored
Merge pull request #88 from onelogin/develop
Move forward with v1
2 parents fb7692b + bc6893d commit 14adaec

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+423
-172
lines changed

.github/workflows/go.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
on: [push, pull_request]
1+
on:
2+
push:
3+
pull_request:
4+
workflow_dispatch:
5+
26
name: CI
37
jobs:
48
tests:
@@ -13,9 +17,5 @@ jobs:
1317
run: go build ./...
1418
- name: Vet
1519
run: go vet ./...
16-
- name: Test
17-
uses: cedrickring/golang-action@master
18-
with:
19-
args: make test
2020
- name: Secure
2121
run: make secure

.github/workflows/release.yml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@ jobs:
77
goreleaser:
88
runs-on: ubuntu-latest
99
steps:
10-
- name: Checkout
11-
uses: actions/checkout@v2
12-
- name: Unshallow
13-
run: git fetch --prune --unshallow
14-
- name: Set up Go
15-
uses: actions/setup-go@v2
10+
- uses: actions/checkout@v3
1611
with:
17-
go-version: 1.14
18-
- name: Release
19-
uses: docker://antonyurchenko/git-release:latest
12+
fetch-depth: 0
13+
- run: git fetch --force --tags
14+
- uses: actions/setup-go@v4
15+
with:
16+
go-version: stable
17+
- uses: goreleaser/goreleaser-action@v4
18+
with:
19+
distribution: goreleaser
20+
version: latest
21+
args: release --clean
2022
env:
2123
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2224
DRAFT_RELEASE: "false"

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2010-2021 OneLogin, Inc.
1+
Copyright (c) 2010-2023 OneLogin, Inc.
22

33
Permission is hereby granted, free of charge, to any person
44
obtaining a copy of this software and associated documentation

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ secure:
1313
./bin/gosec -exclude=G104 ./...
1414

1515
link:
16-
ln -s ${GOPATH}/src/github.com/onelogin/onelogin-go-sdk .
16+
ln -s ${GOPATH}/src/github.com/onelogin/onelogin-go-sdk .

config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version: "4.0.0"
1+
version: "4.0.1"

docs/api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ The `Authenticator` interface is used for handling authentication. It uses the `
3535

3636
The `Authenticator` is initialized with the `NewAuthenticator` function and the token is generated with the `GenerateToken` method within the `NewClient` function. If a request is unauthorized (HTTP 401), the token is refreshed using the `GenerateToken` method in the `sendRequest` function.
3737

38-
In summary, the API module simplifies the process of interacting with the OneLogin API by encapsulating the details of creating, sending, and processing HTTP requests. It uses environment variables for the API credentials and handles error scenarios such as unauthorized requests and token refresh. It forms the backbone of the OneLogin Go SDK, providing a streamlined interface for making API calls.
38+
In summary, the API module simplifies the process of interacting with the OneLogin API by encapsulating the details of creating, sending, and processing HTTP requests. It uses environment variables for the API credentials and handles error scenarios such as unauthorized requests and token refresh. It forms the backbone of the OneLogin Go SDK, providing a streamlined interface for making API calls.

docs/authentication.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ type Authenticator struct {
1414

1515
## NewAuthenticator Function
1616

17-
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`.
17+
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`.
1818

1919
```go
20-
func NewAuthenticator() *Authenticator {
21-
return &Authenticator{}
20+
func NewAuthenticator(subdomain string) *Authenticator {
21+
return &Authenticator{subdomain: subdomain}
2222
}
2323
```
2424

@@ -37,7 +37,7 @@ func (a *Authenticator) GenerateToken() error {
3737
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.
3838

3939
```go
40-
func (a *Authenticator) RevokeToken(token, domain *string) error {
40+
func (a *Authenticator) RevokeToken(token *string) error {
4141
// implementation details
4242
}
4343
```

docs/usage_examples.md

Lines changed: 149 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,106 @@
1+
1. **User model**
2+
13
```go
24
package main
35

46
import (
57
"fmt"
8+
"github.com/onelogin/onelogin-go-sdk/v4/pkg/onelogin/models"
9+
"github.com/onelogin/onelogin-go-sdk/v4/pkg/onelogin"
10+
)
11+
12+
func main() {
13+
var (
14+
email string = "test@example.com"
15+
username string = "testuser"
16+
)
17+
18+
client, err := onelogin.NewOneloginSDK()
19+
if err != nil {
20+
fmt.Println(err)
21+
}
22+
23+
user, err := client.CreateUser(models.User{
24+
Email: &email,
25+
Username: &username,
26+
})
27+
if err != nil {
28+
fmt.Println(err)
29+
}
30+
fmt.Printf("%+v\n", user)
31+
}
32+
```
633

7-
"github.com/onelogin/onelogin-go-sdk/internal/models"
8-
"github.com/onelogin/onelogin-go-sdk/pkg/onelogin"
34+
2. **Role model**
35+
36+
```go
37+
package main
38+
39+
import (
40+
"fmt"
41+
"github.com/onelogin/onelogin-go-sdk/v4/pkg/onelogin/models"
42+
"github.com/onelogin/onelogin-go-sdk/v4/pkg/onelogin"
943
)
1044

1145
func main() {
12-
var testSSO = models.SSOOpenId{ClientID: "1234567890"}
13-
var testConfig = models.ConfigurationOpenId{
14-
RedirectURI: "https://example.com",
15-
LoginURL: "https://example.com/login",
16-
OidcApplicationType: 1,
17-
TokenEndpointAuthMethod: 1,
18-
AccessTokenExpirationMinutes: 60,
19-
RefreshTokenExpirationMinutes: 60,
46+
var (
47+
name string = "Admin"
48+
)
49+
50+
client, err := onelogin.NewOneloginSDK()
51+
if err != nil {
52+
fmt.Println(err)
2053
}
2154

55+
role, err := client.CreateRole(models.Role{
56+
Name: &name,
57+
})
58+
if err != nil {
59+
fmt.Println(err)
60+
}
61+
fmt.Printf("%+v\n", role)
62+
}
63+
```
64+
65+
3. **Event model**
66+
67+
```go
68+
package main
69+
70+
import (
71+
"fmt"
72+
"github.com/onelogin/onelogin-go-sdk/v4/pkg/onelogin/models"
73+
"github.com/onelogin/onelogin-go-sdk/v4/pkg/onelogin"
74+
)
75+
76+
func main() {
77+
client, err := onelogin.NewOneloginSDK()
78+
if err != nil {
79+
fmt.Println(err)
80+
}
81+
82+
eventQ := models.EventQuery{}
83+
eventList, err := client.GetEvents(&eventQ)
84+
if err != nil {
85+
fmt.Println(err)
86+
}
87+
fmt.Printf("%+v\n", eventList)
88+
}
89+
```
90+
91+
92+
4. **App model**
93+
94+
```go
95+
package main
96+
97+
import (
98+
"fmt"
99+
"github.com/onelogin/onelogin-go-sdk/v4/pkg/onelogin/models"
100+
"github.com/onelogin/onelogin-go-sdk/v4/pkg/onelogin"
101+
)
102+
103+
func main() {
22104
var (
23105
connetorid int32 = 108419
24106
name string = "Bow wow wow yippy yo yippy yay"
@@ -29,24 +111,69 @@ func main() {
29111
if err != nil {
30112
fmt.Println(err)
31113
}
32-
appQ := models.AppQuery{}
33-
applist, err := client.GetApps(&appQ)
114+
115+
app, err := client.CreateApp(models.App{
116+
ConnectorID: &connetorid,
117+
Name: &name,
118+
Description: &descr,
119+
})
34120
if err != nil {
35121
fmt.Println(err)
36122
}
37-
fmt.Printf("%+v\n", applist)
123+
fmt.Printf("%+v\n", app)
124+
}
125+
```
38126

39-
appT, err := client.CreateApp(models.App{
40-
ConnectorID: &connetorid,
41-
Name: &name,
42-
Description: &descr,
43-
SSO: testSSO,
44-
Configuration: testConfig,
45-
})
127+
5. **UserMappings model**
128+
129+
```go
130+
package main
131+
132+
import (
133+
"fmt"
134+
"github.com/onelogin/onelogin-go-sdk/v4/pkg/onelogin/models"
135+
"github.com/onelogin/onelogin-go-sdk/v4/pkg/onelogin"
136+
)
137+
138+
func main() {
139+
client, err := onelogin.NewOneloginSDK()
140+
if err != nil {
141+
fmt.Println(err)
142+
}
143+
144+
userMappingsQuery := models.UserMappingsQuery{}
145+
userMappings, err := client.GetUserMappings(&userMappingsQuery)
146+
if err != nil {
147+
fmt.Println(err)
148+
}
149+
fmt.Printf("%+v\n", userMappings)
150+
}
151+
```
152+
153+
6. **AppRule model**
154+
155+
```go
156+
package main
157+
158+
import (
159+
"fmt"
160+
"github.com/onelogin/onelogin-go-sdk/v4/pkg/onelogin/models"
161+
"github.com/onelogin/onelogin-go-sdk/v4/pkg/onelogin"
162+
)
163+
164+
func main() {
165+
client, err := onelogin.NewOneloginSDK()
166+
if err != nil {
167+
fmt.Println(err)
168+
}
169+
170+
appRuleQuery := models.AppRuleQuery{}
171+
appRules, err := client.GetAppRules(&appRuleQuery)
46172
if err != nil {
47173
fmt.Println(err)
48174
}
49-
fmt.Printf("%+v\n", appT)
175+
fmt.Printf("%+v\n", appRules)
50176
}
177+
```
51178

52-
```
179+
Please note that these are basic examples and may not work as expected without proper setup and context. You may need to adjust them according to your needs.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
module github.com/onelogin/onelogin-go-sdk
1+
module github.com/onelogin/onelogin-go-sdk/v4
22

33
go 1.18

main.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/onelogin/onelogin-go-sdk/v4/pkg/onelogin"
8+
"github.com/onelogin/onelogin-go-sdk/v4/pkg/onelogin/models"
9+
)
10+
11+
func main() {
12+
13+
// Set environment variables for OneLogin API credentials
14+
os.Setenv("ONELOGIN_CLIENT_ID", "client_id")
15+
os.Setenv("ONELOGIN_CLIENT_SECRET", "client_secret")
16+
os.Setenv("ONELOGIN_SUBDOMAIN", "your-api-subdomain")
17+
18+
// Create a user object with the specified attributes
19+
UserTwo := models.User{Firstname: "Mikhail", Lastname: "Beaverton", Email: "mb@example.com"}
20+
21+
// Create a user query object with the specified email
22+
UserQueryOne := models.UserQuery{Email: &UserTwo.Email}
23+
24+
// Create a new OneLogin SDK client
25+
Client, err := onelogin.NewOneloginSDK()
26+
if err != nil {
27+
fmt.Println(err)
28+
}
29+
30+
// Create a new user with the specified attributes
31+
Client.CreateUser(models.User{Firstname: "Jane", Lastname: "Pukalava", Email: "jp@example.com"})
32+
33+
// Create a new user with the specified attributes
34+
Client.CreateUser(UserTwo)
35+
36+
// Get a list of users that match the specified query
37+
Client.GetUsers(&UserQueryOne)
38+
}

0 commit comments

Comments
 (0)