Coder Social home page Coder Social logo

stfalcon-studio / socialauthhelper Goto Github PK

View Code? Open in Web Editor NEW
98.0 11.0 21.0 130 KB

Easy social network authorization for Android. Supports Facebook, Twitter, Instagram, Google+, Vkontakte. Made by Stfalcon

Home Page: https://stfalcon.com

Java 100.00%
android facebook twitter instagram googleplus vkontakte authorization

socialauthhelper's Introduction

SocialAuthHelper

A library that helps to implement social network authorization (Facebook, Twitter, Instagram, GooglePlus, Vkontakte).

Who we are

Need iOS and Android apps, MVP development or prototyping? Contact us via [email protected]. We develop software since 2009, and we're known experts in this field. Check out our portfolio and see more libraries from stfalcon-studio.

Download

Download via Gradle:

compile 'com.github.stfalcon:socialauthhelper:0.1'

or Maven:

<dependency>
  <groupId>com.github.stfalcon</groupId>
  <artifactId>socialauthhelper</artifactId>
  <version>0.1.1</version>
  <type>pom</type>
</dependency>

Usage

If you don't use fabric plugin for Android studio, put it into gradle:

repositories {
    maven { url 'https://maven.fabric.io/public' }
}

buildscript {
    repositories {
        mavenCentral()
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}

dependencies {
    //your dependencies
    compile ('com.twitter.sdk.android:twitter:1.13.2@aar') {
        transitive = true;
    }
}

Twitter

Create new application at https://apps.twitter.com
Don't forget to enable: "Allow this application to be used to Sign in with Twitter."
In Application class or initial activity class:

TwitterAuthConfig authConfig = new TwitterAuthConfig(
                getString(R.string.twitterConsumerKey),//twitter application consumer key
                getString(R.string.twitterConsumerSecret));//twitter application consumer secret
//setup fabric
Fabric.with(this, new Twitter(authConfig));

In your activity(fragment) class declare field:

private TwitterClient twitterClient;

In onCreate method:

//create TwitterClient where `this` is your activity
twitterClient = new TwitterClient(this);

//init views
final Button btnTwitter = (Button) findViewById(R.id.btn_twitter);
final TextView tvTwitter = (TextView) findViewById(R.id.tv_twitter);
final ImageView ivTwitter = (ImageView) findViewById(R.id.iv_twitter);

//set onClick event for auth button
btnTwitter.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
      twitterClient.getUser(new TwitterClient.UserLoadListener() {
        @Override
        public void onUserLoaded(User user, String profileImage) {
            //after authorization successful you have access to user profile and Access Token
            tvTwitter.setText(getString(R.string.profileInfo,
                  user.name,
                  user.getId(),
                  twitterClient.getAccessToken()));

            Picasso.with(MainActivity.this).load(profileImage).into(ivTwitter);
      }
});

Override onActivityResult method:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    twitterClient.onActivityResult(requestCode, resultCode, data);
}

Vkontakte

Create new application at https://vk.com/dev
In your activity(fragment) class declare field:

private VkClient vkClient;

In onCreate method:

//create VkClient where `this` is your activity
vkClient = new VkClient(this, //activity or fragment
    getString(R.string.vk_redirect_uri), //vk application redirect uri
    getString(R.string.vk_client_id)); //vk application clientId

//init views
final Button btnVk = (Button) findViewById(R.id.btn_vk);
final TextView tvVk = (TextView) findViewById(R.id.tv_vk);
final ImageView ivVk = (ImageView) findViewById(R.id.iv_vk);
//set onClick event for auth button
btnVk.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            vkClient.getProfile(new VkClient.DataLoadedListener<VkProfile>() {
                @Override
                public void onDataLoaded(VkProfile vkProfile) {
                  //after authorization successful you have access to user profile and Access Token
                  tvVk.setText(getString(R.string.profileInfo,
                      vkProfile.getFirstName() + " " + vkProfile.getLastName(),
                      vkProfile.getId(),
                      vkClient.getAccessToken()));
                      
                  Picasso.with(MainActivity.this).load(vkProfile.getProfilePhoto()).into(ivVk);
                }
            });
        }
});

Override onActivityResult method:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    vkClient.onActivityResult(requestCode, resultCode, data);
}

Facebook

Create new application at https://developers.facebook.com/apps
In AndroidManifest:

<activity
    android:name="com.facebook.FacebookActivity"
    android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
    android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<provider
    android:name="com.facebook.FacebookContentProvider"
    android:authorities="com.facebook.app.FacebookContentProvider<Your facebook application ID>"
    android:exported="true" />
<meta-data
    android:name="com.facebook.sdk.ApplicationId"
    android:value="<Your facebook application ID>" />

In your activity(fragment) class declare field:

private FacebookClient facebookClient;

In onCreate method:

facebookClient = new FacebookClient(this);

//init views
final Button btnFacebook = (Button) findViewById(R.id.btn_facebook);
final TextView tvFacebook = (TextView) findViewById(R.id.tv_facebook);
final ImageView ivFacebook = (ImageView) findViewById(R.id.iv_facebook);

//set onClick event for auth button
btnFacebook.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
    facebookClient.getProfile(new FacebookClient.FbResultCallback() {
        @Override
        public void onProfileLoaded(FacebookProfile facebookProfile) {
            //after authorization successful you have access to user profile and Access Token
            tvFacebook.setText(getString(R.string.profileInfo,
                    facebookProfile.getName(),
                    facebookProfile.getId(),
                    facebookClient.getToken()));
                    
            Picasso.with(MainActivity.this).load(
                    facebookProfile.getPicture().data.url).into(ivFacebook);
        }
    });
}
});

Override onActivityResult method:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    facebookClient.onActivityResult(requestCode, resultCode, data);
}

Google+

Create new application at https://console.developers.google.com/
Don't forget to enable google plus api.
In your activity(fragment) class declare field:

private GooglePlusClient googlePlusClient;

In onCreate method:

googlePlusClient = new GooglePlusClient(this, 
    getString(R.string.googleClientId));//Web client id

//init views
final Button btnGoogle = (Button) findViewById(R.id.btn_google);
final TextView tvGoogle = (TextView) findViewById(R.id.tv_google);
final ImageView ivGoogle = (ImageView) findViewById(R.id.iv_google);
        
//set onClick event for auth button
btnGoogle.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
      googlePlusClient.getProfile(new GooglePlusClient.GooglePlusResultCallback() {
          @Override
          public void onProfileLoaded(GooglePlusProfile googlePlusProfile) {
              //after authorization successful you have access to user profile and Access Token
              tvGoogle.setText(getString(R.string.profileInfo,
                      googlePlusProfile.getName(),
                      googlePlusProfile.getId(),
                      facebookClient.getToken()));
                      
              Picasso.with(MainActivity.this).load(
                      googlePlusProfile.getAvatar()).into(ivGoogle);
          }
      });
    }
});

Override onActivityResult method:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    googlePlusClient.onActivityResult(requestCode, resultCode, data);
}

Instagram

Create new application at https://www.instagram.com/developer/clients/manage/
Don't forget to enable implicit OAuth in application security settings.

In your activity(fragment) class declare field:

private InstagramClient instagramClient;

In onCreate method:

instagramClient = new InstagramClient(this,
                getString(R.string.instagramRedirectUri), //instagram application redirect uri
                getString(R.string.instagramClientId)); //instagram application client id

//init views
final Button btnInstagram = (Button) findViewById(R.id.btn_instagram);
final TextView tvInstagram = (TextView) findViewById(R.id.tv_instagram);
final ImageView ivInstagram = (ImageView) findViewById(R.id.iv_instagram);

//set onClick event for auth button
btnInstagram.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        instagramClient.getProfile(new InstagramClient.DataLoadedListener<InstagramProfile>() {
            @Override
            public void onDataLoaded(InstagramProfile instagramProfile) {
                //after authorization successful you have access to user profile and Access Token
                tvInstagram.setText(getString(R.string.profileInfo,
                        instagramProfile.getFullName(),
                        instagramProfile.getId(),
                        facebookClient.getToken()));
                        
                Picasso.with(MainActivity.this).load(
                        instagramProfile.getProfilePicture()).into(ivInstagram);
            }
        });
    }
});

Override onActivityResult method:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    instagramClient.onActivityResult(requestCode, resultCode, data);
}

Take a look at the sample projects for more information

License

Copyright 2017 stfalcon.com

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

socialauthhelper's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

socialauthhelper's Issues

Suggestions

Can you upload new version with updated dependencies and add ability to disable token caching? As I read in facebook docs, after user has changed his password token must become invalid, but it's not, and user can still get it from cache (preferences) and use. Which is not good.
Also it would be good to have callbacks for logout and unsuccessful login events

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.