Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
J
JWT
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
kis_intern1
JWT
Commits
df17858c
Commit
df17858c
authored
Aug 08, 2023
by
nk161690
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
login
parent
0ebba712
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
45 deletions
+71
-45
UnityProject/Assets/FacebookLogin.cs
UnityProject/Assets/FacebookLogin.cs
+29
-39
UnityProject/Assets/GgPlayLogin.cs
UnityProject/Assets/GgPlayLogin.cs
+42
-6
No files found.
UnityProject/Assets/FacebookLogin.cs
View file @
df17858c
...
...
@@ -4,33 +4,54 @@ using Photon.Pun;
using
Photon.Realtime
;
using
System
;
using
Facebook.Unity
;
using
System.Threading
;
using
System.Collections.Generic
;
public
class
FacebookLogin
:
MonoBehaviour
{
private
readonly
string
[]
facebookPermissions
=
{
"public_profile"
,
"email"
};
private
Log
.
LoginSession
session
=
new
Log
.
LoginSession
();
public
string
Token
;
public
string
Error
;
private
void
Awake
()
{
if
(!
FB
.
IsInitialized
)
{
FB
.
Init
(
OnInitComplete
);
// Initialize the Facebook SDK
FB
.
Init
(
InitCallback
,
OnHideUnity
);
}
else
{
OnInitComplete
();
// Already initialized, signal an app activation App Event
FB
.
ActivateApp
();
}
}
private
void
OnInitComplete
()
void
InitCallback
()
{
if
(
FB
.
IsInitialized
)
{
// Signal an app activation App Event
FB
.
ActivateApp
();
// Continue with Facebook SDK
}
else
{
Debug
.
LogError
(
"Failed to Initialize the Facebook SDK"
);
Debug
.
Log
(
"Failed to Initialize the Facebook SDK"
);
}
}
void
OnHideUnity
(
bool
isGameShown
)
{
if
(!
isGameShown
)
{
// Pause the game - we will need to hide
Time
.
timeScale
=
0
;
}
else
{
// Resume the game - we're getting focus again
Time
.
timeScale
=
1
;
}
}
...
...
@@ -42,21 +63,15 @@ public class FacebookLogin : MonoBehaviour
public
void
OnFacebookLoginButtonClicked
()
{
if
(
FB
.
IsLoggedIn
)
{
HandleLoggedIn
();
}
else
{
FB
.
LogInWithReadPermissions
(
callback
:
OnLoginComplete
);
}
FB
.
Mobile
.
LoginWithTrackingPreference
(
LoginTracking
.
LIMITED
,
callback
:
OnLoginComplete
);
}
private
void
OnLoginComplete
(
ILoginResult
result
)
{
if
(
result
.
Error
==
null
&&
!
result
.
Cancelled
)
if
(
FB
.
IsLoggedIn
)
{
string
accessToken
=
AccessToken
.
CurrentAccessToken
.
TokenString
;
Token
=
accessToken
;
Debug
.
Log
(
"Facebook Login Successful! Access Token: "
+
accessToken
);
// Continue with Photon authentication
...
...
@@ -72,31 +87,6 @@ public class FacebookLogin : MonoBehaviour
}
}
private
void
HandleLoggedIn
()
{
string
accessToken
=
AccessToken
.
CurrentAccessToken
.
TokenString
;
string
userID
=
AccessToken
.
CurrentAccessToken
.
UserId
;
// Request user's Facebook information
FB
.
API
(
"/me?fields=id,name,email"
,
HttpMethod
.
GET
,
OnFacebookGraphAPICallback
);
}
private
void
OnFacebookGraphAPICallback
(
IGraphResult
result
)
{
if
(
string
.
IsNullOrEmpty
(
result
.
Error
))
{
// Handle user's Facebook data
string
userName
=
result
.
ResultDictionary
[
"name"
].
ToString
();
string
userEmail
=
result
.
ResultDictionary
[
"email"
].
ToString
();
Debug
.
Log
(
$"User Name:
{
userName
}
, Email:
{
userEmail
}
"
);
}
else
{
Debug
.
LogError
(
$"Facebook Graph API request failed:
{
result
.
Error
}
"
);
}
}
private
void
OnFacebookLoggedIn
()
{
string
aToken
=
AccessToken
.
CurrentAccessToken
.
TokenString
;
...
...
UnityProject/Assets/GgPlayLogin.cs
View file @
df17858c
...
...
@@ -3,26 +3,62 @@ using GooglePlayGames.BasicApi;
using
System
;
using
TMPro
;
using
UnityEngine
;
using
Unity.Services.Core
;
using
Unity.Services.Authentication
;
using
System.Threading.Tasks
;
public
class
GgPlayLogin
:
MonoBehaviour
{
[
SerializeField
]
private
TextMeshProUGUI
message
;
public
void
OnGgPlayLoginButtonClicked
()
public
string
GooglePlayToken
;
public
string
GooglePlayError
;
public
async
Task
Authenticate
()
{
PlayGamesPlatform
.
Activate
();
PlayGamesPlatform
.
Instance
.
Authenticate
(
ProcessAuthentication
);
}
await
UnityServices
.
InitializeAsync
();
internal
void
ProcessAuthentication
(
SignInStatus
status
)
PlayGamesPlatform
.
Instance
.
Authenticate
((
success
)
=>
{
if
(
statu
s
==
SignInStatus
.
Success
)
if
(
succes
s
==
SignInStatus
.
Success
)
{
message
.
text
=
"Connected"
;
Debug
.
Log
(
"Login with Google was successful."
);
message
.
text
=
"Login with Google was successful."
;
PlayGamesPlatform
.
Instance
.
RequestServerSideAccess
(
true
,
code
=>
{
Debug
.
Log
(
$"Auth code is
{
code
}
"
);
GooglePlayToken
=
code
;
});
}
else
{
GooglePlayError
=
"Failed to retrieve GPG auth code"
;
Debug
.
LogError
(
"Login Unsuccessful"
);
message
.
text
=
"Failed"
;
}
});
await
AuthenticateWithUnity
();
}
private
async
Task
AuthenticateWithUnity
()
{
try
{
await
AuthenticationService
.
Instance
.
SignInWithGoogleAsync
(
GooglePlayToken
);
}
catch
(
AuthenticationException
ex
)
{
Debug
.
LogException
(
ex
);
message
.
text
=
"Failed"
;
throw
;
}
catch
(
RequestFailedException
ex
)
{
Debug
.
LogException
(
ex
);
message
.
text
=
"Failed"
;
throw
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment