PHP Classes

OAuth Garmin

Recommend this page to a friend!

      PHP OAuth Library  >  All threads  >  OAuth Garmin  >  (Un) Subscribe thread alerts  
Subject:OAuth Garmin
Summary:OAuth Garmin
Messages:17
Author:Andrea
Date:2021-07-19 11:49:58
 
  1 - 10   11 - 17  

  1. OAuth Garmin   Reply   Report abuse  
Picture of Andrea Andrea - 2021-07-19 11:49:58
Hola Manuel,

Muchas gracias por tu librería y tus ejemplos. Son de gran ayuda ya que me encontraba muy perdida con la implementación de OAuth.

En mi caso lo estoy utilizando para una autentificación con Garmin Connect.

Estoy usando el archivo login_with_garmin.php y he cambiado $client->redirect_uri (con la url del archivo login_with_garmin.php, no sé si eso es correcto), $client->client_id (con los datos facilitados por Garmin) y $client->client_secret (con los datos facilitados por Garmin).

En oauth_client.php he creado un case 'Garmin2Legged' en la función Inicialize(), indicando el oauth_version, request_token_url, dialog_url y access_token_url.

Mi problema es que después de poner las credenciales,y aceptar el acceso, me redirige a la URL login_with_garmin.php y vuelve a empezar el proceso.
Veo que en la url me pasa el oauth_token y el oauth_verifier

¿podrías indicarme si estoy haciendo un paso incorrectamente?

Muchas gracias por tu ayuda.
Un saludo

  2. Re: OAuth Garmin   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2021-07-20 03:46:37 - In reply to message 1 from Andrea
Hola andrea

Mi lengua materna no es el español. Sin embargo, he vivido 1 año en España, así que intentaré dar lo mejor de mí para explicarme en castellano.

El paquete base usa sesiones PHP. Si las sesiones de PHP no funcionan por alguna razón, es posible que el paquete no funcione debido a eso.

¿Puedes probar lo siguiente?

1. Establezca la opción de depuración en true

$client->debug = true;

2. Establezca el nombre del archivo de registro en la ruta de un archivo local.

$client->log_file_name = 'my_oauth_log_file.txt';

3. Ejecute el script login_with_garmin.php nuevamente

4. Verifique el contenido del archivo de registro my_oauth_log_file.txt y responda aquí con el contenido de ese archivo para verificar qué está sucediendo.

  3. Re: OAuth Garmin   Reply   Report abuse  
Picture of Andrea Andrea - 2021-07-20 10:15:39 - In reply to message 1 from Andrea
Hola Manuel,

Muchísimas gracias por responder y de forma tan rápida.
También agradecerte el esfuerzo por contestar en Español, si te sientes más cómodo puedes responderme en Inglés, lo entiendo bastante bien, pero me cuesta un poco expresarme.

He hecho la prueba que me has indicado y te copio el contenido del archivo log. Comentar que he sustituido el oauth_consumer_key por *********** dado que leí en uno de los hilos de tu foro que le decías a un usuario que esa información es mejor no hacerla pública.


Muchísimas gracias de nuevo.


my_oauth_log_file.txt:

OAuth client: Checking the OAuth token authorization state
OAuth client: The OAuth token is not yet authorized
OAuth client: Checking the OAuth token and verifier
OAuth client: Reset the OAuth token state because token and verifier are not both set
OAuth client: Requesting the unauthorized OAuth token
OAuth client: Accessing the OAuth request token at https://connectapi.garmin.com/oauth-service/oauth/request_token
Connecting to connectapi.garmin.com
Resolving HTTP server domain "connectapi.garmin.com"...
Connecting to HTTP server IP 104.18.119.215 port 443...
Connected to connectapi.garmin.com
C GET /oauth-service/oauth/request_token?oauth_consumer_key=***********&oauth_nonce=86ab0c442de489fe5f256760e7232805&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1626775478&oauth_version=1.0&oauth_callback=https%3A%2F%2Fzonaprivada.entrenopersonal.com%2Fnew%2FsincroGC%2Flogin_with_garmin.php&oauth_signature=YXD8ZQriDJbXnArW180QlqaM2VQ%3D HTTP/1.1
C Host: connectapi.garmin.com
C User-Agent: PHP-OAuth-API (http://www.phpclasses.org/oauth-api $Revision: 1.170 $)
C Accept: */*
C Connection: Keep-Alive
C
S HTTP/1.1 200
S Date: Tue, 20 Jul 2021 10:04:38 GMT
S Content-Type: text/plain;charset=utf-8
S Transfer-Encoding: chunked
S Connection: keep-alive
S CF-Cache-Status: DYNAMIC
S Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
S Server: cloudflare
S CF-RAY: 671b5dd1ece0fa44-AMS
S alt-svc: h3-27=":443"; ma=86400, h3-28=":443"; ma=86400, h3-29=":443"; ma=86400, h3=":443"; ma=86400
S
S 85
S oauth_token=43d26c39-e30c-41af-a0c2-f133c57119e3&oauth_token_secret=VE4hLN6m3vXC4fctwyE2Dc55u0Rsjmk0bXG&oauth_callback_confirmed=true
S 0
S
Keeping the connection alive to connectapi.garmin.com
OAuth client: Redirecting to OAuth Dialog https://connect.garmin.com/oauthConfirm?oauth_token=43d26c39-e30c-41af-a0c2-f133c57119e3&oauth_callback=https%3A%2F%2Fzonaprivada.entrenopersonal.com%2Fnew%2FsincroGC%2Flogin_with_garmin.php
OAuth client: Checking the OAuth token authorization state
OAuth client: The OAuth token is not yet authorized
OAuth client: Checking the OAuth token and verifier
OAuth client: Accessing the OAuth access token at https://connectapi.garmin.com/oauth-service/oauth/access_token
Connecting to connectapi.garmin.com
Resolving HTTP server domain "connectapi.garmin.com"...
Connecting to HTTP server IP 104.18.119.215 port 443...
Connected to connectapi.garmin.com
C GET /oauth-service/oauth/access_token?oauth_consumer_key=***********&oauth_nonce=d10b48d5cfd49b8cd5020b2094035ce0&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1626775490&oauth_version=1.0&oauth_token=43d26c39-e30c-41af-a0c2-f133c57119e3&oauth_signature=cWwR3kAJqNyZ4tLgM06dAsYmta8%3D HTTP/1.1
C Host: connectapi.garmin.com
C User-Agent: PHP-OAuth-API (http://www.phpclasses.org/oauth-api $Revision: 1.170 $)
C Accept: */*
C Connection: Keep-Alive
C
S HTTP/1.1 400
S Date: Tue, 20 Jul 2021 10:04:50 GMT
S Content-Type: text/html;charset=utf-8
S Transfer-Encoding: chunked
S Connection: keep-alive
S content-language: en
S CF-Cache-Status: DYNAMIC
S Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
S Server: cloudflare
S CF-RAY: 671b5e1cfccb1eeb-AMS
S alt-svc: h3-27=":443"; ma=86400, h3-28=":443"; ma=86400, h3-29=":443"; ma=86400, h3=":443"; ma=86400
S
S 55b
S <!doctype html><html lang="en"><head><title>HTTP Status 400 – Bad Request</title><style type="text/css">h1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} h2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} h3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} body {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} b {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} p {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;} a {color:black;} a.name {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 400 – Bad Request</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Message</b> Missing verifier.</p><p><b>Description</b> The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).</p><hr class="line" /><h3>Garmin Connect API Server</h3><script defer src="https://static.cloudflareinsights.com/beacon.min.js" data-cf-beacon='{"rayId":"671b5e1cfccb1eeb","token":"dfcba71ff1d44ca3956104d931b99217","version":"2021.6.0","si":10}'></script>
</body></html>
S 0
S
Keeping the connection alive to connectapi.garmin.com
OAuth client: Could not retrieve the OAuth access token. Error: it was not possible to access the OAuth access token: it was returned an unexpected response status 400 Response: <!doctype html><html lang="en"><head><title>HTTP Status 400 – Bad Request</title><style type="text/css">h1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} h2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} h3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} body {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} b {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} p {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;} a {color:black;} a.name {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 400 – Bad Request</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Message</b> Missing verifier.</p><p><b>Description</b> The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).</p><hr class="line" /><h3>Garmin Connect API Server</h3><script defer src="https://static.cloudflareinsights.com/beacon.min.js" data-cf-beacon='{"rayId":"671b5e1cfccb1eeb","token":"dfcba71ff1d44ca3956104d931b99217","version":"2021.6.0","si":10}'></script>
</body></html>
OAuth client: The OAuth token was authorized
OAuth client: Redirecting to OAuth Dialog https://connect.garmin.com/oauthConfirm?oauth_token=43d26c39-e30c-41af-a0c2-f133c57119e3&oauth_callback=https%3A%2F%2Fzonaprivada.entrenopersonal.com%2Fnew%2FsincroGC%2Flogin_with_garmin.php


  4. Re: OAuth Garmin   Reply   Report abuse  
Picture of Andrea Andrea - 2021-07-20 10:15:42 - In reply to message 1 from Andrea
Hola Manuel,

Muchísimas gracias por responder y de forma tan rápida.
También agradecerte el esfuerzo por contestar en Español, si te sientes más cómodo puedes responderme en Inglés, lo entiendo bastante bien, pero me cuesta un poco expresarme.

He hecho la prueba que me has indicado y te copio el contenido del archivo log. Comentar que he sustituido el oauth_consumer_key por *********** dado que leí en uno de los hilos de tu foro que le decías a un usuario que esa información es mejor no hacerla pública.


Muchísimas gracias de nuevo.


my_oauth_log_file.txt:

OAuth client: Checking the OAuth token authorization state
OAuth client: The OAuth token is not yet authorized
OAuth client: Checking the OAuth token and verifier
OAuth client: Reset the OAuth token state because token and verifier are not both set
OAuth client: Requesting the unauthorized OAuth token
OAuth client: Accessing the OAuth request token at https://connectapi.garmin.com/oauth-service/oauth/request_token
Connecting to connectapi.garmin.com
Resolving HTTP server domain "connectapi.garmin.com"...
Connecting to HTTP server IP 104.18.119.215 port 443...
Connected to connectapi.garmin.com
C GET /oauth-service/oauth/request_token?oauth_consumer_key=***********&oauth_nonce=86ab0c442de489fe5f256760e7232805&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1626775478&oauth_version=1.0&oauth_callback=https%3A%2F%2Fzonaprivada.entrenopersonal.com%2Fnew%2FsincroGC%2Flogin_with_garmin.php&oauth_signature=YXD8ZQriDJbXnArW180QlqaM2VQ%3D HTTP/1.1
C Host: connectapi.garmin.com
C User-Agent: PHP-OAuth-API (http://www.phpclasses.org/oauth-api $Revision: 1.170 $)
C Accept: */*
C Connection: Keep-Alive
C
S HTTP/1.1 200
S Date: Tue, 20 Jul 2021 10:04:38 GMT
S Content-Type: text/plain;charset=utf-8
S Transfer-Encoding: chunked
S Connection: keep-alive
S CF-Cache-Status: DYNAMIC
S Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
S Server: cloudflare
S CF-RAY: 671b5dd1ece0fa44-AMS
S alt-svc: h3-27=":443"; ma=86400, h3-28=":443"; ma=86400, h3-29=":443"; ma=86400, h3=":443"; ma=86400
S
S 85
S oauth_token=43d26c39-e30c-41af-a0c2-f133c57119e3&oauth_token_secret=VE4hLN6m3vXC4fctwyE2Dc55u0Rsjmk0bXG&oauth_callback_confirmed=true
S 0
S
Keeping the connection alive to connectapi.garmin.com
OAuth client: Redirecting to OAuth Dialog https://connect.garmin.com/oauthConfirm?oauth_token=43d26c39-e30c-41af-a0c2-f133c57119e3&oauth_callback=https%3A%2F%2Fzonaprivada.entrenopersonal.com%2Fnew%2FsincroGC%2Flogin_with_garmin.php
OAuth client: Checking the OAuth token authorization state
OAuth client: The OAuth token is not yet authorized
OAuth client: Checking the OAuth token and verifier
OAuth client: Accessing the OAuth access token at https://connectapi.garmin.com/oauth-service/oauth/access_token
Connecting to connectapi.garmin.com
Resolving HTTP server domain "connectapi.garmin.com"...
Connecting to HTTP server IP 104.18.119.215 port 443...
Connected to connectapi.garmin.com
C GET /oauth-service/oauth/access_token?oauth_consumer_key=***********&oauth_nonce=d10b48d5cfd49b8cd5020b2094035ce0&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1626775490&oauth_version=1.0&oauth_token=43d26c39-e30c-41af-a0c2-f133c57119e3&oauth_signature=cWwR3kAJqNyZ4tLgM06dAsYmta8%3D HTTP/1.1
C Host: connectapi.garmin.com
C User-Agent: PHP-OAuth-API (http://www.phpclasses.org/oauth-api $Revision: 1.170 $)
C Accept: */*
C Connection: Keep-Alive
C
S HTTP/1.1 400
S Date: Tue, 20 Jul 2021 10:04:50 GMT
S Content-Type: text/html;charset=utf-8
S Transfer-Encoding: chunked
S Connection: keep-alive
S content-language: en
S CF-Cache-Status: DYNAMIC
S Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
S Server: cloudflare
S CF-RAY: 671b5e1cfccb1eeb-AMS
S alt-svc: h3-27=":443"; ma=86400, h3-28=":443"; ma=86400, h3-29=":443"; ma=86400, h3=":443"; ma=86400
S
S 55b
S <!doctype html><html lang="en"><head><title>HTTP Status 400 – Bad Request</title><style type="text/css">h1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} h2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} h3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} body {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} b {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} p {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;} a {color:black;} a.name {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 400 – Bad Request</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Message</b> Missing verifier.</p><p><b>Description</b> The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).</p><hr class="line" /><h3>Garmin Connect API Server</h3><script defer src="https://static.cloudflareinsights.com/beacon.min.js" data-cf-beacon='{"rayId":"671b5e1cfccb1eeb","token":"dfcba71ff1d44ca3956104d931b99217","version":"2021.6.0","si":10}'></script>
</body></html>
S 0
S
Keeping the connection alive to connectapi.garmin.com
OAuth client: Could not retrieve the OAuth access token. Error: it was not possible to access the OAuth access token: it was returned an unexpected response status 400 Response: <!doctype html><html lang="en"><head><title>HTTP Status 400 – Bad Request</title><style type="text/css">h1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} h2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} h3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} body {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} b {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} p {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;} a {color:black;} a.name {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 400 – Bad Request</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Message</b> Missing verifier.</p><p><b>Description</b> The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).</p><hr class="line" /><h3>Garmin Connect API Server</h3><script defer src="https://static.cloudflareinsights.com/beacon.min.js" data-cf-beacon='{"rayId":"671b5e1cfccb1eeb","token":"dfcba71ff1d44ca3956104d931b99217","version":"2021.6.0","si":10}'></script>
</body></html>
OAuth client: The OAuth token was authorized
OAuth client: Redirecting to OAuth Dialog https://connect.garmin.com/oauthConfirm?oauth_token=43d26c39-e30c-41af-a0c2-f133c57119e3&oauth_callback=https%3A%2F%2Fzonaprivada.entrenopersonal.com%2Fnew%2FsincroGC%2Flogin_with_garmin.php


  5. Re: OAuth Garmin   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2021-07-20 10:37:48 - In reply to message 4 from Andrea
Hello Andrea,

Thank you for accepting that I reply in English.

It seems you are using the 'Garmin' OAuth server configuration.

Can you please check if you have the same problem when using the 'Garmin2Legged' configurations?

  6. Re: OAuth Garmin   Reply   Report abuse  
Picture of Andrea Andrea - 2021-07-20 17:44:04 - In reply to message 5 from Manuel Lemos
Hola Manuel,

Muchas gracias,
Tal vez el problema está en que yo creé un case 'Garmin2Leggend' el el switch($this->server) de la función Initialize() en el archivo oauth_client.php

Lo hice porque veía que no existía el case y que entraba en el default.

Agregué estas líneas de código justo después del case 'Yahoo'.

Te copio lo que puse:
case 'Garmin2Legged':
$this->oauth_version = '1.0';
$this->request_token_url = 'https://connectapi.garmin.com/oauth-service/oauth/request_token';
$this->dialog_url = 'https://connect.garmin.com/oauthConfirm';
$this->access_token_url = 'https://connectapi.garmin.com/oauth-service/oauth/access_token';
$this->authorization_header = false;
break;


Al ver tu respuesta, he probado a quitar este código para dejarlo como estaba y que entre en el default, pero entonces me aparece el siguiente mensaje de error:
OAuth client error
Error: it was not possible to access the OAuth request token: it was returned an unexpected response status 301 Response:




Por si es necesario, te copio también la parte del código que tengo en el login_with_garmin.php donde realicé los cambios (pongo ****** en el client_id y en el client_secret)

$client = new oauth_client_class;
$client->debug = true;
$client->log_file_name = 'my_oauth_log_file.txt';
$client->debug_http = true;
$client->server = 'Garmin2Legged';
$client->redirect_uri = 'https://'.$_SERVER['HTTP_HOST'].
dirname(strtok($_SERVER['REQUEST_URI'],'?')).'/login_with_garmin.php';

$client->client_id = '******';
$application_line = __LINE__;
$client->client_secret = '******';



Muchas gracias por tu atención y tu tiempo.

  7. Re: OAuth Garmin   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2021-07-21 07:00:09 - In reply to message 6 from Andrea
Hello Andrea,

I am very busy this week but I will try to look into this in the upcoming weekend. Can you please reply here if I do not reply until next Monday?

  8. Re: OAuth Garmin   Reply   Report abuse  
Picture of Andrea Andrea - 2021-07-21 08:02:11 - In reply to message 7 from Manuel Lemos
Of course,
Don't worry,
I really appreciate your help and your attention.
Thank you again.
Best regards,
Andrea

  9. Re: OAuth Garmin   Reply   Report abuse  
Picture of Andrea Andrea - 2021-07-27 07:51:33 - In reply to message 8 from Andrea
Good Morning,
I'm sending this message only as a reminder.
I hate to bother you, but the truth is that I really appreciate your help because I can't get it to work.
Thank you very much

  10. Re: OAuth Garmin   Reply   Report abuse  
Picture of Andrea Andrea - 2021-07-27 07:51:39 - In reply to message 8 from Andrea
Good Morning,
I'm sending this message only as a reminder.
I hate to bother you, but the truth is that I really appreciate your help because I can't get it to work.
Thank you very much

 
  1 - 10   11 - 17