Skip to content

Instantly share code, notes, and snippets.

@absowoot
Created April 17, 2023 14:36
Show Gist options
  • Save absowoot/fe67de899b81575fe4b6b5cdb64202db to your computer and use it in GitHub Desktop.
Save absowoot/fe67de899b81575fe4b6b5cdb64202db to your computer and use it in GitHub Desktop.
defmodule WbbRdo.Netsuite do
use Assent.Strategy.OIDC.Base
alias Assent.Config
@impl true
def default_config(config) do
site_prefix =
Config.get(config, :account_id, "")
|> String.replace("_", "-")
app_endpoint = "https://#{site_prefix}.app.netsuite.com"
suitetalk_endpoint = "https://#{site_prefix}.suitetalk.api.netsuite.com"
[
site: suitetalk_endpoint,
openid_configuration: %{
"issuer" => "https://system.netsuite.com",
"authorization_endpoint" => app_endpoint <> "/app/login/oauth2/authorize.nl",
"token_endpoint" => suitetalk_endpoint <> "/services/rest/auth/oauth2/v1/token",
"jwks_uri" => suitetalk_endpoint <> "/services/rest/auth/oauth2/v1/keys",
"token_endpoint_auth_methods_supported" => ["client_secret_basic"]
},
authorization_params: [scope: "email", response_mode: "form_post"],
trusted_audiences:
~w(... ...)
]
end
@impl true
def normalize(_config, user) do
{
:ok,
# Conformed to https://openid.net/specs/openid-connect-core-1_0.html#rfc.section.5.1
%{
"sub" => user["sub"],
"name" => user["name"],
"nickname" => user["username"],
"email" => user["email"]
}
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment