Skip to content
GitLab
Explorer
Connexion
Navigation principale
Rechercher ou aller à…
Projet
PHP
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Wiki
Wiki externe
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Extraits de code
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Déploiement
Releases
Registre de paquets
Registre de conteneurs
Registre de modèles
Opération
Environnements
Modules Terraform
Surveillance
Incidents
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse CI/CD
Données d'analyse du dépôt
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté GitLab
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
ARISE
AriseID Connect
Exemples
PHP
Validations
5cca01da
Valider
5cca01da
rédigé
Il y a 7 ans
par
Aaron Parecki
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
updates for sample github app
parent
c89f1e6b
Branches
Branches contenant la validation
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
1
Afficher les modifications d'espaces
En ligne
Côte à côte
Affichage de
1 fichier modifié
github.php
+17
-16
17 ajouts, 16 suppressions
github.php
avec
17 ajouts
et
16 suppressions
github.php
+
17
−
16
Voir le fichier @
5cca01da
...
@@ -13,24 +13,11 @@ $tokenURL = 'https://github.com/login/oauth/access_token';
...
@@ -13,24 +13,11 @@ $tokenURL = 'https://github.com/login/oauth/access_token';
$apiURLBase
=
'https://api.github.com/'
;
$apiURLBase
=
'https://api.github.com/'
;
// The URL for this script, used as the redirect URL
// The URL for this script, used as the redirect URL
$baseURL
=
'https://'
.
$_SERVER
[
'SERVER_NAME'
]
$baseURL
=
'https://'
.
$_SERVER
[
'SERVER_NAME'
]
.
$_SERVER
[
'PHP_SELF'
];
.
$_SERVER
[
'PHP_SELF'
];
// Start a session so we have a place to store things between redirects
// Start a session so we have a place to store things between redirects
session_start
();
session_start
();
// If there is an access token in the session, the user is logged in
if
(
!
isset
(
$_GET
[
'action'
]))
{
if
(
!
empty
(
$_SESSION
[
'access_token'
]))
{
echo
'<h3>Logged In</h3>'
;
echo
'<p><a href="?action=repos">View Repos</a></p>'
;
echo
'<p><a href="?action=logout">Log Out</a></p>'
;
}
else
{
echo
'<h3>Not logged in</h3>'
;
echo
'<p><a href="?action=login">Log In</a></p>'
;
}
die
();
}
// Start the login process by sending the user to Github's authorization page
// Start the login process by sending the user to Github's authorization page
if
(
isset
(
$_GET
[
'action'
])
&&
$_GET
[
'action'
]
==
'login'
)
{
if
(
isset
(
$_GET
[
'action'
])
&&
$_GET
[
'action'
]
==
'login'
)
{
...
@@ -40,6 +27,7 @@ if(isset($_GET['action']) && $_GET['action'] == 'login') {
...
@@ -40,6 +27,7 @@ if(isset($_GET['action']) && $_GET['action'] == 'login') {
$_SESSION
[
'state'
]
=
bin2hex
(
random_bytes
(
16
));
$_SESSION
[
'state'
]
=
bin2hex
(
random_bytes
(
16
));
$params
=
array
(
$params
=
array
(
'response_type'
=>
'code'
,
'client_id'
=>
$githubClientID
,
'client_id'
=>
$githubClientID
,
'redirect_uri'
=>
$baseURL
,
'redirect_uri'
=>
$baseURL
,
'scope'
=>
'user public_repo'
,
'scope'
=>
'user public_repo'
,
...
@@ -65,7 +53,7 @@ if(isset($_GET['code'])) {
...
@@ -65,7 +53,7 @@ if(isset($_GET['code'])) {
die
();
die
();
}
}
// Exchange the auth code for a token
// Exchange the auth code for a
n access
token
$token
=
apiRequest
(
$tokenURL
,
array
(
$token
=
apiRequest
(
$tokenURL
,
array
(
'grant_type'
=>
'authorization_code'
,
'grant_type'
=>
'authorization_code'
,
'client_id'
=>
$githubClientID
,
'client_id'
=>
$githubClientID
,
...
@@ -96,6 +84,19 @@ if(isset($_GET['action']) && $_GET['action'] == 'repos') {
...
@@ -96,6 +84,19 @@ if(isset($_GET['action']) && $_GET['action'] == 'repos') {
die
();
die
();
}
}
// If there is an access token in the session, the user is logged in
if
(
!
isset
(
$_GET
[
'action'
]))
{
if
(
!
empty
(
$_SESSION
[
'access_token'
]))
{
echo
'<h3>Logged In</h3>'
;
echo
'<p><a href="?action=repos">View Repos</a></p>'
;
echo
'<p><a href="?action=logout">Log Out</a></p>'
;
}
else
{
echo
'<h3>Not logged in</h3>'
;
echo
'<p><a href="?action=login">Log In</a></p>'
;
}
die
();
}
// This helper function will make API requests to GitHub, setting
// This helper function will make API requests to GitHub, setting
// the appropriate headers GitHub expects, and decoding the JSON response
// the appropriate headers GitHub expects, and decoding the JSON response
...
@@ -107,7 +108,7 @@ function apiRequest($url, $post=FALSE, $headers=array()) {
...
@@ -107,7 +108,7 @@ function apiRequest($url, $post=FALSE, $headers=array()) {
curl_setopt
(
$ch
,
CURLOPT_POSTFIELDS
,
http_build_query
(
$post
));
curl_setopt
(
$ch
,
CURLOPT_POSTFIELDS
,
http_build_query
(
$post
));
$headers
=
[
$headers
=
[
'Accept: application/vnd.github.v3+json'
,
'Accept: application/vnd.github.v3+json
, application/json
'
,
'User-Agent: https://example-app.com/'
'User-Agent: https://example-app.com/'
];
];
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter