0

I'm using ruby version 2.2.10p489 and Rails version 5.1.6. I am attempting to use the omnicontacts gem to import Hotmail contacts into my application using the oauth2 flow.

I was following the instructions listed at https://github.com/Diego81/omnicontacts.

Below is my config/initializers/omnicontacts.rb configuration file:

require "omnicontacts"

Rails.application.middleware.use OmniContacts::Builder do
    importer :hotmail, ENV['MICROSOFT_APP_ID'],  ENV['MICROSOFT_APP_SECRET'], {:redirect_path => "/contacts/import/hotmail_or_other/"}
end

When I visit https://6663cb10.ngrok.io/contacts/hotmail as per Diego's instructions on the omnicontacts page, I'm not redirected to the sign on page for Microsoft. Instead I'm automatically sent to the show action of the Contacts controller with the following parameters:

{"error_message"=>"not_authorized", "importer"=>"hotmail", "id"=>"failure"}

If I enter the oauth2 url

 https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=*CLIENT ID HERE*&response_type=id_token&redirect_uri=https%3A%2F%2F6663cb10.ngrok.io%2Fcontacts%2Fimport%2Fhotmail_or_other%2F&scope=openid&response_mode=fragment&state=12345&nonce=678910

directly into my web browser, I am able to type in my e-mail address, but when I click "Next," I am again automatically sent to the show action of the Contacts controller with the following parameters:

{"error_message"=>"not_authorized", "importer"=>"hotmail", "id"=>"failure"}

Below is my Microsoft Application configuration,

Redirect URL: https://6663cb10.ngrok.io/contacts/import/hotmail_or_other/

Logout URL: https://6663cb10.ngrok.io/logout

Delegated Permissions: Contacts.Read, User.Read

Homepage URL: https://6663cb10.ngrok.io/login

I've also noticed the following in the console, but not sure how to address that or if it is really relevant:

app/controllers/contacts_controller.rb:43:in `show'
Started HEAD "/contacts/hotmail" for 163.172.103.81 at 2019-01-05 15:00:03 -0500
Cannot render console from 163.172.103.81! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Started HEAD "/contacts/hotmail" for 2a02:4780:1:3::15 at 2019-01-05 15:00:56 -0500
Cannot render console from 2a02:4780:1:3::15! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Started HEAD "/contacts/hotmail" for 51.15.164.30 at 2019-01-05 15:01:02 -0500
Cannot render console from 51.15.164.30! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Started HEAD "/contacts/hotmail" for 51.15.164.31 at 2019-01-05 15:04:03 -0500
Cannot render console from 51.15.164.31! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255

Here is my config/routes.rb file:

Rails.application.routes.draw do

  mount Ckeditor::Engine => '/ckeditor'

  get 'password_resets/new'
  get 'password_resets/edit'
  get 'sessions/new'

  root 'static_pages#home'

  get '/help',           to: 'static_pages#help'
  get '/about',          to: 'static_pages#about'
  get '/contact_us',        to: 'static_pages#contact_us'

  get '/signup',         to: 'users#new'
  post '/signup',        to: 'users#create'

  get '/login',          to: 'sessions#new'
  post '/login',         to: 'sessions#create'
  delete '/logout',      to: 'sessions#destroy'

  get '/pictures/new/:id/imageable_type/:type', to: 'pictures#new', as: 'new_picture'

  get '/contacts/import/google/start', to: 'contacts#import_from_google_start', as: 'new_from_google_contacts'
  get '/contacts/import/google', to: 'contacts#import_from_google', as: 'create_from_google_contacts'

  get '/contacts/import/hotmail_or_other/start', to: 'contacts#import_hotmail_and_or_yahoo_contacts_start', as: 'new_from_hotmail_and_or_yahoo_contacts'
  get '/contacts/import/hotmail_or_other/', to: 'contacts#import_hotmail_and_or_yahoo_contacts', as: 'create_from_hotmail_and_or_yahoo_contacts'


  resources :account_activations, only: [:edit]
  resources :password_resets, only: [:new, :create, :edit, :update] 
  resources :pictures, only: [ :create, :update, :destroy]     
  resources :contacts
  resources :users
  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html

end

Dale K
  • 25,246
  • 15
  • 42
  • 71
Davie Overman
  • 114
  • 1
  • 13
  • Please do not post images of plaintext. [Images of plaintext are not appropriate on StackOverflow](https://meta.stackoverflow.com/a/285557/3784008). You have access to the plaintext; please copy and paste it into your question. Also, please [reformat your code](https://stackoverflow.com/help/formatting) using the linked guide. Properly formatting your post increases the likelihood of you receiving a constructive response. – anothermh Jan 05 '19 at 20:13
  • Would you be able to post your `config/routes.rb` file? – Viktor Nonov Jan 05 '19 at 22:00
  • I edited my question to include the config/routes.rb file. Thanks for your help. – Davie Overman Jan 06 '19 at 19:38

0 Answers0