Class: OmniAuth::Strategies::Notion
- Inherits:
-
OAuth2
- Object
- OAuth2
- OmniAuth::Strategies::Notion
- Defined in:
- lib/omniauth-notion.rb
Instance Method Summary collapse
- #basic_auth_header ⇒ Object
-
#build_access_token ⇒ Object
The Notion API requires HTTP Basic Authentication when exchanging the code for a token (i.e. when POSTing to /v1/oauth/token) Notion Docs: developers.notion.com/docs/authorization#exchanging-the-grant-for-an-access-token Similar solution: gist.github.com/handylearn/6d6125263d32544c2057#file-filab_strategy-rb-L35.
- #callback_url ⇒ Object
-
#query_string ⇒ Object
def callback_url # If redirect_uri is configured in token_params, use that # value.
-
#raw_info ⇒ Object
The Notion API gives us some core data as part of the token response.
Instance Method Details
#basic_auth_header ⇒ Object
58 59 60 |
# File 'lib/omniauth-notion.rb', line 58 def basic_auth_header "Basic " + Base64.strict_encode64("#{[:client_id]}:#{[:client_secret]}") end |
#build_access_token ⇒ Object
The Notion API requires HTTP Basic Authentication when exchanging the code for a token (i.e. when POSTing to /v1/oauth/token)
Notion Docs: https://developers.notion.com/docs/authorization#exchanging-the-grant-for-an-access-token
Similar solution: https://gist.github.com/handylearn/6d6125263d32544c2057#file-filab_strategy-rb-L35
51 52 53 54 55 56 |
# File 'lib/omniauth-notion.rb', line 51 def build_access_token .token_params.merge!( headers: { 'Authorization' => basic_auth_header }, ) super end |
#callback_url ⇒ Object
70 71 72 |
# File 'lib/omniauth-notion.rb', line 70 def callback_url full_host + script_name + callback_path end |
#query_string ⇒ Object
def callback_url
# If redirect_uri is configured in token_params, use that
# value.
token_params.to_hash(symbolize_keys: true)[:redirect_uri] || super
end
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/omniauth-notion.rb', line 88 def query_string # This method is called by callback_url, only if redirect_uri # is omitted in token_params. if request.params['code'] # If this is a callback, ignore query parameters added by # the provider. '' else super end end |
#raw_info ⇒ Object
The Notion API gives us some core data as part of the token response. I don’t think there is a separate /user/me endpoint (at least as of May 2021). Also, we get a ‘bot_id`, not a real user ID. We do get some informaton about the connector Organization, however.
66 67 68 |
# File 'lib/omniauth-notion.rb', line 66 def raw_info @raw_info ||= access_token.params.except('access_token', 'bearer') end |