New to swift and i'm trying to test the login functions on an app I'm trying to make but I cant seem to get the app to "log out" and act as a first time user.
Have this little bit of code to check the login status, but it keeps giving me my auth uid. Im using sign in with apple and firebase
Before I run it I clean the build folder, delete the user from firebase, delete the app from my phone, and make sure the app has been removed from the "Apps using apple id" setting. But it still prints out the auth id when I run it on my phone.
.onAppear(perform: {
Auth.auth().addStateDidChangeListener() { auth, user in
if user != nil {
if Auth.auth().currentUser?.uid != nil {
showLogin = false
print("on appear auth id")
print(Auth.auth().currentUser?.uid)
}else{
showLogin = true
}
} else {
showLogin = true
}
}
})
.fullScreenCover(isPresented: $showLogin, content: Login.init)
Related
I wanted to log username, in case of a login failed scenario in the wso2 identity server using adaptive authentication
code snippet for adaptive authentication
var abc = function(context) {
executeStep(1, {
onSuccess: function (context) {
var user = context.currentKnownSubject;
}
}
},
onFail: function (context){
var username = context.request.params.userame;
var user = context.currentKnownSubject;
//i have used these two approach but the username is coming as null
}
});
};
Could anyone please help with how to do it?
var user = context.currentKnownSubject; or var user = context.steps[1].subject (change the authentication step inside [] as required) can be used to refer the authenticated user object that represents the user details.
So, on the successful authentication step, you can get the authenticated user's username by
context.steps[1].subject.username or context.currentKnownSubject.username
Since there is no authenticated subject set on authentication failure, we can't access the user details from context.currentKnownSubject / context.steps[1].subject under onFail function.(Related issue: https://github.com/wso2/product-is/issues/3950).
But you can retrieve the user input username as context.request.params.username[0] (NOTE: var username = context.request.params.userame; in your code has a typo; userame)
Try the following:
var onLoginRequest = function(context) {
executeStep(1, {
onSuccess: function (context) {
Log.info('Username: ' + context.steps[1].subject.username);
Log.info('Username: ' + context.currentKnownSubject.username);
},
onFail: function (context){
Log.info('Username: ' + context.request.params.username[0]);
}
});
};
Try adding the following.
Log.info('User ' + context.currentKnownSubject.identifier);
I would not recommend logging the username when you are in a production environment because it can reveal sensitive information about the user (if you are using the email as the username). Make sure to remove the logs (comment them) once you are in production.
You can find more information about adaptive auth in here.
in my django project, i have a url that has login_required set, because i need the request.user variable in it to process some data,
i also created a simple chrome extension where i'm going to have to send requests to that django project url.
i do not want to use the username and password in the extension to login and send the request
i want to:
redirect the user when the extension is installed to the my website
they will login,
the extension will know that the user has logged in and it will get (and save) a key that i could maybe inject in the page after login is successful
the key can be used as a query parameter in the request in order to identify the user without any username and password
i'm sorry if this seems as a stupid question, but i'm very confused on how to do this
PS: i have already a system in place where the user can use a key in order to make requests without logging in,
i just need a way to open a tab when the extension is installed, and login then get the key (which is injected in the page after login), and save it to use it in the extension later.
When the extension is opened for the first time, I'm showing the user a login page. The login page sends the username & password to an API where they are authenticated. If the information is correct, the required user info is returned (mainly the API key). The information is then saved to local storage.
var username = document.querySelector('[name="username"]');
var password = document.querySelector('[name="password"]');
$.ajax({
URL : 'https://example.com/api/extension-auth/',
type: 'POST',
crossDomain: true,
data: JSON.stringify({
'username': username.value.trim(),
'password': password.value.trim(),
}),
success: res => {
if (res.api_key) {
browser.storage.sync.set({ 'user_data': {'api_key': api_key} }, () => {
// show extension main logged in page
});
}
else {
// show invalid login information alert
}
},
error: function (err) {
// show server error aler
},
});
Everytime the extension is opened the local storage is checked
browser.storage.sync.get('user_data', data => {
if (data.user_data) {
if (valid_api_key(data.user_data.api_key)) {
// show extension main logged in page
}
else {
// show login page
}
}
else {
// show login page
}
});
the valid_api_key function makes a random call to the API to check if there is not an authentication error.
Then, I use the saved API key from local storage to do API requests.
I have implemented the facebook login for my ionic application, which works perfectly when run on web. When i build the application, create an apk of the same, and try to run on my mobile device, nothing happens.
The login is:
openFB.login(
function (response) {
if (response.status === 'connected') {
console.log('Facebook login succeeded, got access token: ', response);
openFB.api({
path: '/me',
success: function (data) {
console.log("My Data", data);
userData.name = data.name;
userData.picture = 'http://graph.facebook.com/' + data.id + '/picture?type=small';
localStorageService.set('user', userData);
$timeout(function() {
$state.go('app.home');
}, 0);
},
error: function(error) {
console.log("Error here:", error);
}
});
} else {
console.log('Facebook login failed: ' + response);
}
}, { scope: 'email, public_profile' });
Have used openFB for the login. After clicking, following popup comes up.
After clicking the okay, nothing gets logged. No console message.
Can some one help me for finding out this issue, where i am not able to do the facebook login, when run on actual device.
You need to whitelist the redirect url. You can set it in
Products > Facebook Login > Settings > Client OAuth Settings
Take a look into this question.
please set redirect URI in
Products > Facebook Login > Settings > Client OAuth Settings
http://localhost/callback
please follow the below procedure to register your app in facebook developer site
https://ccoenraets.github.io/ionic-tutorial/ionic-facebook-integration.html
and use the below code to complete the procedure of facebook login
$cordovaOauth.facebook("appId", ["email", "public_profile"]).then(function(result) {
//alert(JSON.stringify(result));
//$localStorage.accessToken = result.access_token;
$http.get("https://graph.facebook.com/v2.2/me", {
params: {
access_token: result.access_token,
fields: "id,name,gender,location,email,picture,relationship_status",
format: "json"
}
}).then(function(result) {
// alert(JSON.stringify(result));
$scope.loginflowusingsociallogin(result.data.email);
}, function(error) {
alert("There was a problem getting your profile. Check the logs for details.");
alert(JSON.stringify(error));
});
});
i used Oauth 2.0 authentication for ionic.
I used this code and worked fine for me
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
response.authResponse is null
i have developed one facebook page with apps,
what i want is whenever any user visit my page, the user is served by one popup message, the popup will disappear only when user click "like" button, if user has already liked the page, popup will not appear, to do this i have write following code
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
var user_id = response.authResponse.userID;
var page_id = "app_id";
var fql_query = "SELECT uid FROM page_fan WHERE page_id = "+page_id+"and uid="+user_id;
var the_query = FB.Data.query(fql_query);
the_query.wait(function(rows) {
if (rows.length == 1 && rows[0].uid == user_id) {
alert("liked the page");
popup.hide() // hide the popup as user has clicked like button
}
else {
alert("not liked ");
}
});
}
else if (response.status === 'not_authorized') {
}
else
{
alert("not logged in");
}
});
the above code works fine with only one FB user, one which is admin of this page, for all other user it returns response.status === 'not_authorized' status, so i'm unable to retrieve the user login information, because in this case i'm getting null response.authResponse
do anyone have any idea, how to check login status for all users, not for admin only...??
thanks.
If you are talking about a page tab app and all you want to know is the "like" status of the visiting user then all you have to do is parse the signed_request passed to your app. You can read more about using and parsing Signed Requests here.
In the signed_request there is a user object - the information you need is in that object.
i have a question.... i am actually developing a facebook application with FB javascript SDK. In my application I need email permission for further processing. i am using
FB.Connect.showPermissionDialog("email");
but some how the dialog doesn't appears... here is my code
<script>
appid = '*************';
name = 'Palmchip Test App';
href = 'https://apps.facebook.com/*********/';
FB.init({
appId:appid, cookie:true,
status:true, xfbml:true
});
FB.getLoginStatus(function(response) {
if (response.session) {
alert("You are logged in...");
FB.Connect.showPermissionDialog("email", function(perms) {
if (!perms) {
alert("no access");
} else {
alert("accessed...");
}
});
}
else {
top.location.href='https://graph.facebook.com/oauth/authorize?client_id='+appid+'&redirect_uri='+href+'&display=page';
}
});
</script>
the alert which says you are logged in... works fine but then nothing happens .....
You need to upgrade to OAuth 2.0 ouath: true
You should use the new OAuth Dialog
You should be aware when upgrading that FB.getLoginStatus() will return different objects: response.authResponse
Try this code block
FB.init({appId: <?= APP_ID ?>, status: true, cookie: true, xfbml: true, oauth:true});
function getin(){
FB.login(function(response) {
if (response.authResponse) {
var regurl = "/login";
location.href=regurl;
} else {
var regurl = "/logout";
window.location.href=regurl;
}
}, {scope:'email'});
}
So when you call the getin() function , if the current user already gave you the email address it'll do nothing for him just will redirect him to /login url , but if the user is a new user then he/she will see a pop-up box asking for the email address once he/she allows that you can pull the email address using graph or fql. BTW response inside FB.login has the user id , access_toke and some more useful data so save that for further use.