Code Monkey home page Code Monkey logo

onelogin-go-sdk's Introduction

OneLogin CLI

Go Report Card gopherbadger-tag-do-not-edit

Description

The OneLogin CLI is your way to manage OneLogin resources such as Apps, Users, and Mappings via the Command Line.

Get Started

Install From Source - Requires Go

clone this repository from inside the repository go build ./... to create a runnable binary from inside the repository go install . to add a the runnable CLI to your GOPATH /bin directory

Alternatively you may run make install which just runs the above commands

Install with Homebrew (Mac OS Only)

brew install onelogin/tap-onelogin/onelogin

Or brew tap onelogin/tap-onelogin and then brew install onelogin.

Binaries

There are binaries available for the major platforms in this project's /build directory. Download the binary for your system and add it to your /bin folder or run it directly per your system's requirements.

  • darwin-amd64 => mac 64 bit and linux
  • windows-386 => windows 32 bit
  • windows-amd64 => windows 64 bit
  • linux-386 => linux 32 bit
  • linux-amd64 => linux 64 bit

Install Binary on Mac

Download and extract the darwin-amd64 package from the release artifacts list

tar -xvf darwin-amd64.tar.gz && sudo mv build/darwin-amd64/onelogin-darwin-amd64 /usr/local/bin/onelogin (you can specifiy a different name to invoke such as usr/local/bin/ol)

You'll likely get hit with a security warning when you try running onelogin for the first time.

To fix, go to System Preferences > Security & Privacy

you'll be presented with the warning about the binary not being from an identified developer. Allow this app to run.

Try running the command again and click Open from the popup and you should be good to go.

Install Binary on Windows

Download and extract the windows-amd64 package from the release artifacts list

Navigate to the extracted folder which should be in your Downloads folder and navigate to the .exe file (build > windows-amd64).

Create a folder in Program Files (Program Files \ Onelogin) and add the .exe to that folder.

Add Program Files \ Onelogin to your path by changing the environment variables

Hit the window key and type path. Select "Edit the system environment variables" Toward the bottom on the Advanced tab, select "Environment Variables" In the System variables list, click the Path variable on the list and click "Edit" Click "New" and add C:\Program Files\Onelogin Click OK on all the windows

Open a Cmd window and start using onelogin

/usr/local/bin/onelogin

Features

onelogin profiles [action] <profile_name> Maintains a listing of accounts used by the CLI in a home/.onelogin/profiles file and facilitates creating, changing, deleting, indexing, and using known configurations. You are of course, free to go and edit the profiles file yourself and use this as a way to quickly switch out your environment. Available Actions:

use             [name - required] => CLI will use this profile's credentials in all requests to OneLogin
show            [name - required] => shows information about the profile
edit   (update) [name - required] => edits selected profile information
remove (delete) [name - required] => removes selected profile
add    (create) [name - required] => adds profile to manage
list   (ls)     [name - optional] => lists managed profile that can be used. if name given, lists information about that profile
which  (current)                  => returns current active profile

onelogin smarthooks [action] <id> Creates a .js and .json file with the configuration needed for a Smart Hook and its backing javascript code. Available Actions:

new                                        => creates a new smart hook project in a sub-directory of the current working directory, with the given name and hook type.
list                                       => lists the hook IDs and types of hooks associated to your account.
deploy                                     => deploys the smart hook defined in the hook.js and hook.json files in the current working directory via a create/update request to OneLogin API.
test                                       => passes an example context defined in context.json to the hook code and runs it in lambda-local.
get         [id - required]                => creates a new smart hook project from an existing hook in OneLogin in current directory. ⚠️ Will overwrite existing project! To track changes or treat smart hook like a NodeJS project use a VCS.
delete      [ids - required]               => accepts a list of IDs to be destroyed via a delete request to OneLogin API.

env_vars                                   => lists the defined environment variable names. E.g. environment variables like FOO=bar BING=baz would turn up [FOO, BING].
put_env_vars [key=value pairs - required]  => creates or updates the environment variable with the given key. Must be given as FOO=bar BING=baz.
rm_env_vars  [key - required]              => deletes the environment variable with the given key.

terraform-import <resource>: Import your remote resources into a local Terraform State. Running this command will do the following:

  1. Pull all your resources from the OneLogin API (remote)
  2. Establish a basic main.tf that represents all the apps in your account. Each app will get an empty Terraform resource "placeholder"
  3. Call terraform import for all the apps and update the .tfstate
  4. Using .tfstate, update main.tf to fill in the editable fields of the resource

Profiles

Add your OneLogin profiles with onelogin profiles add <profile_name>

You'll be prompted for your client_id and client_secret (obtained by creating a set of developer keys in the onelogin admin portal)

You can add as many profiles as you like, and you can switch the active profile with onelogin profiles use <profile_name> which will point the CLI at the active account.

Smart Hooks

From an empty directory, where you plan to manage your Smart Hook run: onelogin smarthooks create

Select the hook type from the propmpt and you'll be presented with some files

hook.json - Config file for your Smart Hook where you can modify things like timeout and retries.

⚠️   Do NOT modify the function, env_vars, packages, or type! This tool will handle that for you.

hook.js - The good stuff. This is your Smart Hook code that gets run every time the triggering event happens.

⚠️   Do not remove the exports line. Smart Hooks use exports.handler = async (context) => {} as its main function.

⚠️   You must also return from your code an object with the success node defined. In a new project, this defaults to return {success: true}

.env - Where you manage environment variables as you would in other NodeJS projects

.gitignore - Lists things that are not recommended for check in to version control (like test artifacts, and .env)


To apply changes to your Smart Hook, call the onelogin smarthooks save command from inside the directory containing hook.js and hook.json

Create an empty Smart Hook project

onelogin smarthooks create

Update a Smart Hook

onelogin smarthooks save

To run tests against your Smart Hook code:

  • Create a context.json file (the input to the function). You can get one for Pre-Authentication or User-Migration
  • Run onelogin smarthooks test from inside your Smart Hook Project
  • Results will print to the screen

Terraform Import

Import all OneLogin apps, create a main.tf file, and establish Terraform state.

From an empty directory, where you plan to manage your main.tf file run:

onelogin terraform-import onelogin_apps

If you have pre-existing resources defined in main.tf the tool is smart enough to merge those definitions.

Contributing

Generally

Fork this repository, make your change and submit a PR to this repository against the develop branch.

Adding Resources for Import - Terraform Importer

To add an importable resource, do these things:

  1. Under the terraform/importables directory, add a file with the scheme _.go
  2. Add a struct to represent your importable, add whatever filtering or special criteria fields you need. OneLogin importables typically have at least a field for the resource's service from our SDK.
  3. On that struct you just made, implement the Importable interface. this is where we pull all the resources from the remote/api and represent them as resources in terraform
  4. Add structs that represent the fields you want to pull from tfstate into main.tf after the import for users to manage later. the state struct is how a resource is represented in .tfstate so in order for json marshalling to work, this struct has to look like your resource in tfstate.
  5. Refer to this in terraform/import/state.go in the 'molds' section so the importer is aware of the fields that should be read from tfstate and will marshal the respective data.
  6. in cmd/terraform-import add to the importables struct <resource_name>: tfimportables.YourImportable{} to register it

onelogin-go-sdk's People

Contributors

at-k avatar brahmlower avatar bzvestey avatar dbourdrez avatar dcaponi avatar ebarti avatar gkhaburzaniya-onelogin avatar gmlexx avatar gwadley avatar jmfwolf avatar melchiormoulin avatar not-ol-github avatar stijndcl avatar subterrane avatar valeriy24 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

onelogin-go-sdk's Issues

null pointer in SDK crashes OL terraform provider

Having an issue onelogin/terraform-provider-onelogin/issues/83 with the OL Terraform provider crashing.

After digging more into the problem, it looks like the problem might be in this library the TF provider depends on. The error message is

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x100faa144]

I'm more or less a Golang novice, but it looks like the problem in this library is services/apps/v2.go#L175:

func (svc *V2Service) pruneParameters(requestedParams map[string]AppParameters, app *App) error {
	var delErrors []error
	keepMap := make(map[int32]bool, len(requestedParams))
	for _, param := range requestedParams {
		keepMap[*param.ID] = true     ## <-- crash happens here
	}
        ...

I'm not sure why, but when trying to use the TF provider to modify an existing resource, param.ID is nil here which results in the crash. Using the TF provider to create a onelogin_saml_apps resource appears to work (the tf-apply completes), but when you run tf-plan it wants to make changes to the resource, as if it wasn't applied correctly the first time. When running tf-apply again to modify/update the OL SAML app is when the crash happens.

Screenshot attached below showing the run state immediately before golang drops into the panic handler.

Stack trace from the terraform-provider-onelogin plugin:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x102759b40]

goroutine 83 [running]:
github.com/onelogin/onelogin-go-sdk/pkg/services/apps.(*V2Service).pruneParameters(0x1400071ca50, 0x1400022ef70, 0x14000736420)
	/Users/rhornsby/go/pkg/mod/github.com/onelogin/[email protected]/pkg/services/apps/v2.go:175 +0xd0
github.com/onelogin/onelogin-go-sdk/pkg/services/apps.(*V2Service).Update(0x1400071ca50, 0x14000736420)
	/Users/rhornsby/go/pkg/mod/github.com/onelogin/[email protected]/pkg/services/apps/v2.go:142 +0x2f8
github.com/onelogin/terraform-provider-onelogin/onelogin.samlAppUpdate(0x140000e8d80, {0x1028dab60?, 0x1400071e230})
	/Users/rhornsby/projects/work/esp/golang/terraform-provider-onelogin/onelogin/resource_onelogin_saml_apps.go:136 +0x63c
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).update(0x10292a0e0?, {0x1029f24d8?, 0x140002f4a40?}, 0x24?, {0x1028dab60?, 0x1400071e230?})
	/Users/rhornsby/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:302 +0x58
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0x14000234cc0, {0x1029f24d8, 0x140002f4a40}, 0x14000738700, 0x140004aba20, {0x1028dab60, 0x1400071e230})
	/Users/rhornsby/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:404 +0x478
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0x140001ab2c0, {0x1029f24d8, 0x140002f4a40}, 0x140006143c0)
	/Users/rhornsby/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:955 +0x868
github.com/hashicorp/terraform-plugin-go/tfprotov5/server.(*server).ApplyResourceChange(0x140001cf600, {0x1029f2580?, 0x14000197f80?}, 0x140005dea00?)
	/Users/rhornsby/go/pkg/mod/github.com/hashicorp/[email protected]/tfprotov5/server/server.go:332 +0x64
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x1029be040?, 0x140001cf600}, {0x1029f2580, 0x14000197f80}, 0x1400007e3c0, 0x0)
	/Users/rhornsby/go/pkg/mod/github.com/hashicorp/[email protected]/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:380 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0x140002a6fc0, {0x1029f5c98, 0x140004fa000}, 0x1400035e000, 0x14000397950, 0x102e09b00, 0x0)
	/Users/rhornsby/go/pkg/mod/google.golang.org/[email protected]/server.go:1194 +0xadc
google.golang.org/grpc.(*Server).handleStream(0x140002a6fc0, {0x1029f5c98, 0x140004fa000}, 0x1400035e000, 0x0)
	/Users/rhornsby/go/pkg/mod/google.golang.org/[email protected]/server.go:1517 +0x82c
google.golang.org/grpc.(*Server).serveStreams.func1.2()
	/Users/rhornsby/go/pkg/mod/google.golang.org/[email protected]/server.go:859 +0x84
created by google.golang.org/grpc.(*Server).serveStreams.func1
	/Users/rhornsby/go/pkg/mod/google.golang.org/[email protected]/server.go:857 +0x290

Error: The terraform-provider-onelogin plugin crashed!

This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.

Screen Shot 2022-11-08 at 21 42 34

Propagate context to API request

Hello,

Appriciate your quick response for my previous issue.

Is there any estimation that you will implement the API requests using NewRequestWithContext so we will be able to pass our context?

Thanks in advanced.

Getting user application entitlements

Hello,
I'm trying call OneLogin APIs to see which users have which entitlements to an application.

First, is there a way to query for the entitlements a user has to an application directly? For example, if I am using the Amazon Web Services (AWS) Multi Account connector, I'd like to see which users have access to which IAM roles.

Second, if it is not possible to get that information directly, is the recommended approach to have the client parse the app's App Rules to determine entitlements? If so, is there a recommended way of doing this? I've started to attempt this myself, but I do not see how to access the List App Users API using this SDK – is that possible?

Thanks

Pagination doesn't work for GetUsers, etc

When I call GetUsers with a UserQuery{Page: "1"}, I get an error Failed to get user: json: cannot unmarshal string into Go value of type []string. Can you provide a working example of pagination using pages and cursors? It's also unclear how I would get back the cursor information from the response, as it's in the response header which it seems is not processed and returned by GetUsers.

Setting any value in the UserQuery fails with the same error: Failed to get user: json: cannot unmarshal string into Go value of type []string

Support for request/response logging?

I had originally made a request here in the terraform-provider-onlogin repo to add support for onelogin API request/response debug logging.

Other providers include support for this and it helps tremendously troubleshooting issue and communicating with provider developers sharing log output. Terraform writes about implementing provider logging here

I've attached an example below of logging coming from the terraform-gsuite-provider visible when we set the TF_LOG env variable to debug:

Obviously this repo is not specific to terraform but this the repo the terraform-onelogin-provider uses as the client for the API, so changes might be made here to provide a way for terraform to capture where it wants to send the logs to which in the case of terraform I beleive would just be to stderr.

Thanks.

Doug

Example API request/response logging coming from the terraform-gsuite-provider:

2021-06-12T10:48:16.543-0400 [WARN]  ValidateProviderConfig from "provider[\"registry.terraform.io/onelogin/onelogin\"]" changed the config value, but that value is unused
2021-06-12T10:48:16.543-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62: 2021/06/12 10:48:16 [DEBUG] Waiting for state to become: [success]
2021-06-12T10:48:16.544-0400 [DEBUG] ReferenceTransformer: "data.onelogin_user.self" references: []
2021-06-12T10:48:16.544-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62: 2021/06/12 10:48:16 [DEBUG] Google API Request Details:
2021-06-12T10:48:16.544-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62: ---[ REQUEST ]---------------------------------------
2021-06-12T10:48:16.544-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62: GET /admin/directory/v1/groups/REDACTED?alt=json&prettyPrint=false HTTP/1.1
2021-06-12T10:48:16.544-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62: Host: admin.googleapis.com
2021-06-12T10:48:16.544-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62: User-Agent: google-api-go-client/0.5 (darwin amd64) Terraform/0.15.3
2021-06-12T10:48:16.544-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62: X-Goog-Api-Client: gl-go/1.16.3 gdcl/REDACTED
2021-06-12T10:48:16.544-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62: Accept-Encoding: gzip
2021-06-12T10:48:16.544-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62:
2021-06-12T10:48:16.544-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62:
2021-06-12T10:48:16.544-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62: -----------------------------------------------------
2021-06-12T10:48:16.957-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62: 2021/06/12 10:48:16 [DEBUG] Google API Response Details:
2021-06-12T10:48:16.957-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62: ---[ RESPONSE ]--------------------------------------
2021-06-12T10:48:16.957-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62: HTTP/2.0 200 OK
...
2021-06-12T10:48:16.957-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62: Cache-Control: private
2021-06-12T10:48:16.957-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62: Content-Type: application/json; charset=UTF-8
2021-06-12T10:48:16.957-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62: Date: Sat, 12 Jun 2021 14:48:17 GMT
2021-06-12T10:48:16.957-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62: Etag: "REDACTED"
2021-06-12T10:48:16.957-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62: Server: ESF
2021-06-12T10:48:16.957-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62: Vary: Origin
2021-06-12T10:48:16.957-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62: Vary: X-Origin
2021-06-12T10:48:16.957-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62: Vary: Referer
2021-06-12T10:48:16.957-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62: X-Content-Type-Options: nosniff
2021-06-12T10:48:16.957-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62: X-Frame-Options: SAMEORIGIN
2021-06-12T10:48:16.957-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62: X-Xss-Protection: 0
2021-06-12T10:48:16.957-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62:
2021-06-12T10:48:16.957-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62: {
2021-06-12T10:48:16.958-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62:  "kind": "admin#directory#group",
2021-06-12T10:48:16.958-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62:  "id": "REDACTED",
2021-06-12T10:48:16.958-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62:  "etag": "REDACTED",
2021-06-12T10:48:16.958-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62:  "email": "REDACTED",
2021-06-12T10:48:16.958-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62:  "name": "REDACTED",
2021-06-12T10:48:16.958-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62:  "directMembersCount": "2",
2021-06-12T10:48:16.958-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62:  "description": "REDACTED",
2021-06-12T10:48:16.958-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62:  "adminCreated": true,
2021-06-12T10:48:16.958-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62:  "nonEditableAliases": [
2021-06-12T10:48:16.958-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62:   "REDACTED",
2021-06-12T10:48:16.958-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62:   "REDACTED"
2021-06-12T10:48:16.958-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62:  ]
2021-06-12T10:48:16.958-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62: }
2021-06-12T10:48:16.958-0400 [DEBUG] provider.terraform-provider-gsuite_v0.1.62: -----------------------------------------------------

Infinite loop when getting 401

Hi,
I send my requests with bearer authorization method. (API Credentials)
In case I get 401 there is an infinite loop to generate a new bearer token
We may try one more time but why forever?

Thanks in advanced

case resp.StatusCode == http.StatusUnauthorized, resp.StatusCode == http.StatusForbidden:

if resourceRequest.AuthMethod == "bearer" {
	if err := setBearerToken(svc); err != nil {
		return nil, nil, err
	}
	return svc.executeHTTP(req, resourceRequest)
}

return nil, nil, customerrors.OneloginErrorWrapper(svc.ErrorContext, errors.New("unauthorized"))

How to create SAML 2.0 Advanced connector?

Hello,

Is there any way to create a new app with connector_id = 110016 with defined configuration?

Currently I can create an app with empty logout_url, audience, consumer_url, etc configuration fields

  "configuration": {
    "logout_url": "https://{{ website_name}}.{{ website_domain}}/auth/?sls",
    "saml_notonorafter": "3",
    "audience": "https://{{ website_name}}.{{ website_domain}}/auth/metadata/",
    "generate_attribute_value_tags": "0",
    "saml_initiater_id": "0",
    "saml_notbefore": "3",
    "saml_issuer_type": "0",
    "saml_sign_element": "0",
    "encrypt_assertion": "1",
    "consumer_url": "https://{{ website_name}}.{{ website_domain}}/auth/?acs",
    "login": "https://{{ website_name}}.{{ website_domain}}/",
    "saml_sessionnotonorafter": "1440",
    "saml_encryption_method_id": "0",
    "recipient": "https://{{ website_name}}.{{ website_domain}}/auth/?acs",
    "validator": ".*",
    "signature_algorithm": "SHA-1",
    "relaystate": "https://{{ website_name}}.{{ website_domain}}/",
    "saml_nameid_format_id": "0"
  }

Bug on usage of Queryable (interface) feature(s)

On Validators

QueryValidators are not taking into consideration the pointer types.
Take into consideration the UserQuery.email, that matches the for the validation.validateString validates a string, but the query struct olds a (pointer) *string:

type UserQuery struct {
        // ... other values
        Email          *string    `json:"email,omitempty"`
        // ... other values
}

func (q *UserQuery) GetKeyValidators() map[string]func(interface{}) bool {
	return map[string]func(interface{}) bool{
		// ... other values
		"email":          validateString,
		// ... other values
	}
}

func validateString(val interface{}) bool {
	_, ok := val.(string)
	return ok
}

A simple example (given mostly from the docs example), proves that failure:

func main() {
	ol, err := onelogin.NewOneloginSDK()
	if err != nil {
		fmt.Println("Unable to initialize client:", err)
		return
	}

	email := "[email protected]"
	userQuery := &models.UserQuery{
		Email: &email,
	}
	userList, err := ol.GetUsers(userQuery)
	if err != nil {
		fmt.Println("Failed to get user:", err) // <-- enters here
		return
	}

	fmt.Println(userList)
}

Although this was just tested with the example provided,
I believe this can be happening in more places.

On request payload

Keeping the same example as the above, even if the validators are bypassed, when we are trying to setup the request to be made, the AddQueryToPath invoking its neighbour function queryToValues fail to setup the URL query parameters from the Queryable interface previously given to it.

Extra

  • Is there any other way of using this?
  • Can someone share a workable snippet?

[BUG] Authentication fails because of incorrect API url

The API docs mention that the correct url to authenticate is https://<subdomain>.onelogin.com/auth/oauth2/v2/token. This is easy to confirm by sending a request to it.

The SDK constructs this subdomain URL correctly when creating a client:

subdomain := os.Getenv("ONELOGIN_SUBDOMAIN")
old := fmt.Sprintf("https://%s.onelogin.com", subdomain)

However, the Authenticator completely ignores this and hardcodes the URL without region in the subdomain:

// Construct the authentication URL
authURL := fmt.Sprintf("https://api.onelogin.com%s", TkPath)

Hence, every request fails without much to do about it.

The subdomain URL should also be used for authentication (both generating & revoking tokens). It is generated one line before invoking the GenerateToken() method in NewClient(), so it can be passed in as a parameter.

SAML assertion

Hi, I forked the project to try and add SAML assertion support, as I'm trying to migrate a Python application that requires this.
It basically works, as long as I don't have an error during the authentication, as it enters a loop in olhttp.executeHTTP to try and fetch a new Bearer token -- it doesn't distinguish between a SAML authn error and a OAuth one.

Check PR #30 as an initial work. The diff in client.go is due to VS Code import reordering.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.