0

I implemented the outlook REST api on my Rails app following this official tutorial: https://dev.outlook.com/restapi/tutorial/ruby By the way, it needs to be updated. Outlook now requires more permissions ('profile') to get the email of the user in the auth controller:

SCOPES = [ 'openid', 'profile', 'https://outlook.office.com/mail.read' ]

Anyhow, I am storing the email and token after authenticating, but that token is very short lived. I need a way to permanently store authentication for the user. When I run things as suggested and want to get the emails the response is:

...
  response_headers: !ruby/hash-with-ivars:Faraday::Utils::Headers
    elements:
      content-length: '0'
      server: Microsoft-IIS/8.5
      set-cookie: exchangecookie=afaeef5a8a6747aab24dad1ddb97a8fb; expires=Fri, 16-Jun-2017
        00:07:54 GMT; path=/; HttpOnly
      www-authenticate: Bearer client_id="00000002-0000-0ff1-ce00-000000000000", trusted_issuers="00000001-0000-0000-c000-000000000000@*",
        token_types="app_asserted_user_v1 service_asserted_app_v1", authorization_uri="https://login.windows.net/common/oauth2/authorize",
        error="invalid_token",Basic Realm="",Basic Realm=""
      request-id: c59488ab-62b5-4a9f-a3f5-43bda739c9ab
      x-calculatedbetarget: BLUPR07MB260.namprd07.prod.outlook.com
      x-backendhttpstatus: '401'
      x-ms-diagnostics: '2000010;reason="ErrorCode: ''PP_E_RPS_REASON_TIMEWINDOW_EXPIRED''.
        Message: ''Failed the Validate call, reason: Time window expired.%0d%0a''";error_category="invalid_msa_ticket"'
      x-diaginfo: BLUPR07MB260
      x-beserver: BLUPR07MB260
      x-powered-by: ASP.NET
      x-feserver: BN3PR16CA0057
      x-msedge-ref: 'Ref A: 3E2E02429DE244F7A738A7BE6CF9E06B Ref B: CAA6321D024D5B725BA8FFE7DAC85411
        Ref C: Wed Jun 15 17:07:54 2016 PST'
      date: Thu, 16 Jun 2016 00:07:54 GMT
      connection: close
    ivars:
      :@names:
        content-length: content-length
        server: server
        set-cookie: set-cookie
        www-authenticate: www-authenticate
        request-id: request-id
        x-calculatedbetarget: x-calculatedbetarget
        x-backendhttpstatus: x-backendhttpstatus
        x-ms-diagnostics: x-ms-diagnostics
        x-diaginfo: x-diaginfo
        x-beserver: x-beserver
        x-powered-by: x-powered-by
        x-feserver: x-feserver
        x-msedge-ref: x-msedge-ref
        date: date
        connection: connection
  status: 401

How do I adjust this code to store a permanent token?

Ben
  • 2,957
  • 2
  • 27
  • 55

1 Answers1

0

OK< I found a few answers on StackOverflow for different stacks. I would normally delete my post, but for Rails developer who may need this, the answer to my questions is simply adding 'offline_access' to SCOPES = [ 'openid', 'profile', 'offline_access', 'https://outlook.office.com/mail.read' ]

Ben
  • 2,957
  • 2
  • 27
  • 55