Skip to content

Commit

Permalink
Fix endpoint and JSON payload
Browse files Browse the repository at this point in the history
Looks like OneLogin has changed the following endpoint:

/auth/oauth2/token -> /auth/oauth2/v2/token

In addition, the /api/1/saml_assertion endpoint started to return
HTTP 500 when the ip_address field is included with an empty value.
  • Loading branch information
johananl committed Sep 6, 2018
1 parent 02e3917 commit 8f13fe8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 33 deletions.
23 changes: 7 additions & 16 deletions onelogin/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,19 @@ type GenerateTokensParams struct {
}

type GenerateTokensResponse struct {
Status struct {
Error bool `json:"error"`
Code int `json:"code"`
Type string `json:"type"`
Message string `json:"message"`
} `json:"status"`
Data []struct {
AccessToken string `json:"access_token"`
CreatedAt time.Time `json:"created_at"`
ExpiresIn int `json:"expires_in"`
RefreshToken string `json:"refresh_token"`
TokenType string `json:"token_type"`
AccountID int `json:"account_id"`
} `json:"data"`
AccessToken string `json:"access_token"`
CreatedAt time.Time `json:"created_at"`
ExpiresIn int `json:"expires_in"`
RefreshToken string `json:"refresh_token"`
TokenType string `json:"token_type"`
AccountID int `json:"account_id"`
}

type GenerateSamlAssertionParams struct {
UsernameOrEmail string `json:"username_or_email"`
Password string `json:"password"`
AppId string `json:"app_id"`
Subdomain string `json:"subdomain"`
IpAddress string `json:"ip_address"`
}

// TODO This one assumes MFA is enabled. Need to handle all cases.
Expand Down Expand Up @@ -164,7 +155,7 @@ func (c *Client) GenerateTokens(clientID, clientSecret string) (string, error) {

// TODO add handling for valid JSON with wrong response

return resp.Data[0].AccessToken, nil
return resp.AccessToken, nil
}

// GenerateSamlAssertion gets a OneLogin access token and a GenerateSamlAssertionParams struct
Expand Down
22 changes: 6 additions & 16 deletions onelogin/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,12 @@ func TestNewClient(t *testing.T) {

func TestGenerateTokens(t *testing.T) {
data := `{
"status": {
"error": false,
"code": 200,
"type": "success",
"message": "Success"
},
"data": [
{
"access_token": "fake_token",
"created_at": "2015-11-11T03:36:18.714Z",
"expires_in": 36000,
"refresh_token": "fake",
"token_type": "bearer",
"account_id": 555555
}
]
"access_token": "fake_token",
"created_at": "2015-11-11T03:36:18.714Z",
"expires_in": 36000,
"refresh_token": "fake",
"token_type": "bearer",
"account_id": 555555
}`

ts := getTestServer(data)
Expand Down
2 changes: 1 addition & 1 deletion onelogin/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const (
euBase = "https://api.eu.onelogin.com"

GenerateSamlAssertionPath string = "/api/1/saml_assertion"
GenerateTokensPath string = "/auth/oauth2/token"
GenerateTokensPath string = "/auth/oauth2/v2/token"
GetUserByEmailPath string = "/api/1/users?email=%s"
VerifyFactorPath string = "/api/1/saml_assertion/verify_factor"
)
Expand Down

0 comments on commit 8f13fe8

Please sign in to comment.