e�se?�Google Playe??e??Androida?�c�?cs�a?Za?�e?�?��

a��e??a?�cs�Androida?�c�?e????�?Y?c�?cs�???aS?a�?a?Za?�c�????a??a�?a�?a?�a?�?��??�a��a??a???????�c��a?�cs�??????a?�c�?a?Ye?�e�?a??a�?cZ�a��cs�e�?a?�c??a?�a��a??e�?e�?a?Za?�cs�?��a��i??a?�e?�e�?a�?cs�a?�a??e��e?????i?sa?Za?�c?�a??a��a?�cY?e?�a�?a??a?�c�?a??a�?a�?a??e??i??a�?a?Sa�?a??c�???�a??a??c�?a�?a��

a?�a??e????�a�?a�???�c�?a?�c�?a??e??cs�HTTPc�?c�?i??a?�??????aS?a�?c�?c?�a??a��a?�c?�a�s???e�?a??a?�e�??�????c��???aS?a�?i?Y??�c�Yi??a��a?�a??e??a??a�?a�Za��a?�a?�?�?a?�e�?HTTP POSTe?�?��i??a��?z?a��a��e??c??a?�c�???�cs�e?�a�?i??a��a��a??a�?a??e?�???a?�cs�c�???�a?�i?Y
a??c��aS?e�?a��a?Se�??��c�???�e?�a�?c�???�a??a�?a?�c�????a??a��cs�c�???�a?�e??a��c�?a?�???i??a��?z??Y?a??c�???�a��e?�a?�cs�a?�c�?i??a�?e�?a�?a??c�?Interneta?�a?�cY?e?�a?�a?�cs�e?�a�?i??a��a��a??e??a�?e?�c?�c?�a��a?�a�za?Si??cZ�a??a???��??�a�?a�?Androidc�???�2.2??�?�?e�?c�???�cs�e�?a��a?Si??Google Play???aS????a?�a?�a?�a??aY?a?ZGooglee?�a?�cs�e�?a�??�????a��

a?�e??

??� a��a�?e???��e?�e?�a??a�s?�?e?�cs�e?�c?�i??a?�???a?�e?????a?�a??c��cY�cs�c�???�i?sa?�a??a�?a??c�?Google Play???aS?a?�GoogleAuthUtilc��???eZ�a?�a?�a??a?�a?sa�?e?�a�?a��c�?i??ID Tokeni?�a�?cs�a��c��a??a��a?�e�?e??a��c�?a?�a?�cs�a?Za?�i??c��a?Za?�cs�a?Za?�a??a�?a??c�?a�????a?�e�Y?�?a??cs�e??e??a�?a??a?�c�?a?�e�?a?�e??a��c�?a�?a?Se�?a??c�???�a??a??c�?e??a?�c�?a��

e??e??Androida?�c�?cs�a?Za?�e?�?��

e??e??Androida?�c�?cs�a?Za?�e?�?��

e?�a??aSYe??a�?c�??�?a??Googlecs�e�??�?a?�i??a?�a��App Enginecs�?��cs�a?�c�?c�?aSYe??i??e?�a??aSYe???SSa?�c�?c?�a??/a?Zc�?e?�a�?a?????a?�a??c��a?�c?�c?�???az�a��

cZ�a??e��??�a��a?�a��e�?c��eS�a?�a��

a?�c�????a�?

a??a?�c�????a�?e?�c?�a?�i??a?�a��a??a?�a??c�?a??c�?a?�Google API?Z�a?�a?�a��a???��i??a?�e?�e�?a?�a�?a?�a???��e??c��a��e�?c��a?�a??a�?c��e?�a??e??c��a?�a??a�?a?�cs�a?�??�a??e?�?��cs�a??a��a�?a?Sa?�a??a�?a??cs�?��e?�i??a?�a�ze��a?Sa???��e?�c?�a?�i????�a��a?�a??e?�e�?e?�a?�a??e??a��
a?�a?Ya??a�??Z????a��e�?cs�Google APIs???e�?c��e?�a??e??c��i??a?�???a?�a�za??c��???i??a?�a??e?�e�?e?�a?�a??e??a��
a?�e?�e�?e��c?Ye�?e��a?�e�??�?a��e�????a??e?�a??e??c��cs�???a�?i??a��a??e?�a?�???a�????a??e�?e�?cs�c�?c?�e��e�?a��

a?�a�?c�???�ID

a?� a��e?�e�?a??a?�cs�e??c��a?�a�?a?�a??a??a??cs�OAuth 2.0 a�?c�???�IDa�?a��c��a?�a?????a�?Weba?�c�?c�???�IDa�?a��a???��cs�i??a?�a??a�?a??c�??��??�cs�?��c�?a�?a�?c�??Z?a??cs�a??e??i??a?�a??e?�e�?a?�a??c?�e��???a?? a�?9414861317621.apps.googleusercontent.coma�?e?�?��cs�c�???�IDa��c��a??a��

cZ�a??a?�e?�e�?a??a?�cs� Androida?�c�?a?�a�?a?�a?�a??c�???�IDa��a???��i??a?�e?�e�????a?�a?�???a?????i?sa?�cs�a?�c�?cs�c?�a??a?�a??c��a�?e??a?�c�?a??a��c?�a??a?�a??c��a��???a??a?�cs�Android.xmla?�e?�a�� a�?packagea�?a�z?��a?�cs�Javae?Z?�?cs�a??a?�DNSi??a?�a��com.example.identitya��

a??c�?a?�e??cs�shella�?a��???eZ�a?�a?�cs�e??a?�c�?a??i?s
$ keytool -exportcert -alias <a?�e�?a??> -keystore <a?�e�?a?�?��a��> -v -list

a�?a?�a??a??”SHA1″cs�a��a??a��eS�i??c??e??e?�a�?Developer Consolea�?cs�a��?��i??c��a?Za?�a�?a?�a?�c�?cs�c�???�IDa��a???��i??a?�c?Y?�?e?�e�?cs�a?????c�???�IDa��c��a??a��

a??a?�cs�Anroida?�c�?a?�

a?� e?�e�?e�?c�?Google Play???aS?a?�cs�GoogleAuthUtilc��a�?eZ�a?�a?�a??IDa��c�?i?�e?�a??e?�c?�a?sa??a�?eZ�a?�a?�a??e�?e��a��c�?a�?e??a?�a?�e�?e�?a��a?�e?�e�??�?a��????�? getToken(email, scope)?�???�a?�cs�scopea?�?��cs�a�?a��a�?a?�e?�???audience:server:client_id:Xi??X??�cs�???a?Se??a��c�?Weba?�c�?cs�c�???�IDa��a�� ?z???�a��cs�Weba?�c�?cs�c�???�ID??????a?Se??a?�a�?a?�cs�a�?i??e�?a??scopea?�?��a�?a?�e????? audience:server:client_id:9414861317621.apps.googleusercontent.com.

a?�e??a?�c�Y

e�s a????�a��a?�i??a?�a?�e?�?��OAutha��c�?cs�?��a��i???�?a??a??c�?e�?a��cs�c�???�a?sc?�a?�a?�a??e??e��c�???�???a?�a�?e�?a??c�?c�???�cs�e?�a�????eZ�a?�?Y?a?�e��???cs�???c�?a��a?�???e?�a????�a??a?�i??c?�c�Ya?sa?? a?�cs�scopea?�?��a?�?Y?e?????aS?a�?c�?c�???�IDi??a?�cZ�e?�a??e??c��a�?a?�cs�Androida?�c�????a??a??a?�a??e??c��a?�i??c��a?Za??a??e?�e�?c�???�a??e?�cs�??�a��a?�c��a?�a��c�?a��a��a��a�?c�?e�� a??a?�a??a???Z�a?�e??e??c��cs�a?�a?�e��cs�a�?c?�a��

a?�e�?a��c�?

a?�a?�a��a��a?�a��a�?a?�cs�???aS?a�?a?Za?�a??e???��i??a?�e?�e�?a?�e�?a?�a?�a�?eZ�a?�cs�a��c�?c��???aS?a�?a?Za?�a��??�a??cs�aSz??�a��???a??POST?�????a?�a?�e�?a��c�?i?�a?�a?Ya??a�??SSa��c�??�?a??a?�a??URLa?�?��a?�i??a?�???i??a��a��a?se?�c?�c�Ye��a?�a��a??a?�e???�?a�?a?�e�?a??a�?c??e��a?�cs�a��c�?i??a?�a?�e?�a??c�?HTTPSe?z?Z?a��

?????�a?�e�?e?�e??a�sa?�cs�?��??�a?�e?�a��a?�a��a?�e�?a?�e�?e�?a?�?��??�a?�a?Za?�i??a??e�??SSe?�a�?a��c�??�?a??a?�a??e??a��cs�a?�?��a?�a��a??a?�a��

a??c�?a��c�?

a?�a?�cs�???aS?a�??��a?�a�Za?�cs�Androida?�c�?a?�???cs�a��c�?a?Zi??e??e??a��c�????a??e�?e�?cs�a��e?�a??e?�c?�e?�e�?a?�?�?i?s
e??e??e??a��c�?a��c�????Googlec�?a??cs�a��
e??e??e??a��c�?a??a?�??�a��a??c�?a��

e??e??c�?a??

a��c�?a?se?�a?�a??Googlecs�a��a��/c�???�a?�e�?a??c�?a??a��e�?a?�Googlea?sa?? www.googleapis.com/oauth2/v1/certsa?�a??a��a?�a?�e�?i??c�?a??a?s?�?a??i?�a��aZ�c?�c?�a?�a��

a?�a?�e?�e??e??a?�eZ�a?�cs�IDa��c�?i??a�ze��a?Se?�a�?a��c�?a��???a?�a??JSON?�?a??cs�Weba��c�?i??e??a��c�????c��e?�a?�a?Se??c?�a?�???a?�cs�e??a?�a?�a?�c�?a??cs�a��a??e??cs�???i????�a?�a?�a??a??e��cs�c��a?�???a?se?�a?�i?�a????�c?�a?sa�?a?�i????�a��a��c�?Java, Ruby, a�?a?SPHP.

e?�a?�c��a?�a??a�?c?�a�?Googlee??a?�i??e�?a?�a??a??e?�e�?cs�?��a��a?�?��e??a?�i??a��?��e??e??e?�c?�i??a��e??a?�??�a��a?�i?�???a?�a??a?�e�Ye?�?�?cs�e�?c�?a��

e??e??a��c�?a��?��

IDa��c�???�a?�a??JSON?�?a??cs�??�?�?e?Ye??i??a��a�s?��cs�e??e??c�?a??cs�c��a?�a?Ya?s?SSa�?a�?a�?a????�e��?��??�a��a�???�e��a��a��cs�?�?a??e?�a�zc��a?�a��a��?��i??a?�a??a�?e?�a?�a�?a??cs�a��?��??�a��aud,azpi??email
a��
e��a�?i??a?�e�??Y?c?�a??a??audcs�a��?��i??e??e?????a?�a?�cs�c�???�IDi??a?�a??Androida?�c�?a?�scopea?�?��a�?i?�a?�e�?a��e?�a??e�?a??c�?e?�a?�?�?i??a��?z?a?�a??e??e??IDa��c�?i??e�?a??a��a��cs�a?�a?�e��a??a�?a??e��e?�?��??????a?�a?�a��

a?�a��a?�e??a??a�??�???�e?�e�??Y?c?�a??a??azpi???�?a??a�??Z?????�?(authorized party)a�?i?�cs�a��?��i??e??e??e??a��?��???a?�a�?a?�Androida?�c�?cs�c�???�IDa?�?��a��?��a��i??a?�a??a�?a??e?�a��e??c��a?�??�a??a??Androida�???�c�?a?�c�?i??a?�e�???�a?�e�?cs�c�???�e?�a�?a��

a?�e�?a?�a�?c�?a�????a?�e?�a?�a��a?�i??e�?a??i??a?�a��a?�e??cY?e?�

1i??e??a��c�????Googlea?�a??cs�a��

2i??e??a��c�?e?�a?�e�?a?�a?�a??e�?a��a?Si??a?�a?�a??c�?e??e�?a��cs�c�???�IDa????�?�?e?Ye??a?�emaila��?��a�?a��

a?�a?Ya?sa??a?�e??cs�a?�a????�a??a??i?s

3i??e??a��c�????a�ZAndroida?�c�?a?�eZ�a?�cs�i??a?�a?�e??a?�c�?cs�IDa????�?�?e?Ye??a?�azpa��?��a�?a��

c�???�e?�a�?a??e????�a�?e�?a?�a??a??a�?e�?a?????a�?a�?a??a��i??a��a??a??a�?a�?cs�??�e��a�?c�?ROOTcs�Anroide�?a��a??a�?c???�?e??a?????a��a?�???a��a��a??a??e??a??e��Googlec�?a????�e��a?�Googlee��e??e�?a��cs�c�???�a��

?Z?a?�???i?Y

e�?a��c?�a?�cs�a?�a�� a?�cY?e?�a?�a??a�?e�?a�?a?Sa�?a??a?�c�?a??e??i???Z?a?�???e�?a??e??a?????a?sa��a??a��a�?c?�a?�cs�a?�a��

a�?c�?c��?��

import java.io.IOException;
import java.security.GeneralSecurityException;

import com.google.api.client.googleapis.auth.oauth2.GoogleIdToken;
import com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.gson.GsonFactory;

public class Checker {

    private final List mClientIDs;
    private final String mAudience;
    private final GoogleIdTokenVerifier mVerifier;
    private final JsonFactory mJFactory;
    private String mProblem = "Verification failed. (Time-out?)";

    public Checker(String[] clientIDs, String audience) {
        mClientIDs = Arrays.asList(clientIDs);
        mAudience = audience;
        NetHttpTransport transport = new NetHttpTransport();
        mJFactory = new GsonFactory();
        mVerifier = new GoogleIdTokenVerifier(transport, mJFactory);
    }

    public GoogleIdToken.Payload check(String tokenString) {
        GoogleIdToken.Payload payload = null;
        try {
            GoogleIdToken token = GoogleIdToken.parse(mJFactory, tokenString);
            if (mVerifier.verify(token)) {
                GoogleIdToken.Payload tempPayload = token.getPayload();
                if (!tempPayload.getAudience().equals(mAudience))
                    mProblem = "Audience mismatch";
                else if (!mClientIDs.contains(tempPayload.getIssuee()))
                    mProblem = "Client ID mismatch";
                else
                    payload = tempPayload;
            }
        } catch (GeneralSecurityException e) {
            mProblem = "Security issue: " + e.getLocalizedMessage();
        } catch (IOException e) {
            mProblem = "Network problem: " + e.getLocalizedMessage();
        }
        return payload;
    }

    public String problem() {
        return mProblem;
    }
}

a?�e?????a?�a??a??c�?Google Javac��a?�a�zcZ�a?�e?�a�?-a��c�?e??e??cs�Javac��i?s

require 'google-id-token'
validator = GoogleIDToken::Validator.new
jwt = validator.check(token, required_audience, required_client_id)
if jwt
  email = jwt['email']
else
  report "Cannot validate: #{validator.problem}"
end

a��?z?a?�???c�?Ruby???a�zcZ�i??a?�e?�e�?a��e?� google-id-token side effects of clomid, purchase lioresal. Ruby gemi??a?�a?�a?sa?�a??e?�?��cs�a??e??i?s

require 'google-id-token'
validator = GoogleIDToken::Validator.new
jwt = validator.check(token, required_audience, required_client_id)
if jwt
  email = jwt['email']
else
  report "Cannot validate: #{validator.problem}"
end

a??PHPc?�a??a�?i??a?�c��Google APIs Client Library for PHPi??c�?a?�???a??apiOAuth2.phpa?�cs�verifyIdToken?�???�a��

 

e��?��aZY?��i?sAndroid Official Blogi??c?�e?�i?sImportNewA�- e�?e��

e?�?��e�??Z?i?shttp://www.importnew.com/3115.html

a�?a��e?�e?�e??i??e?�a???�??��a?�?��???a?�a??c��aZY?��e�??Z?a�?e?�?��e�??Z?a�?e?�e��c��a?????i??e�?e�?a??a??i??a��

 

关于作者: 魏铮

一只热爱生活的程序猿

查看魏铮的更多文章 >>



可能感兴趣的文章

发表评论

Comment form

(*) 表示必填项

还没有评论。

跳到底部
返回顶部