Last active
December 26, 2016 12:16
-
-
Save gambare/49354047b390999756b88130b8262544 to your computer and use it in GitHub Desktop.
webviewでGoogleのOAuth認証を行う ref: http://qiita.com/gambare/items/7af00ad4c953aed9b11e
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {AngularFireModule} from 'angularfire2'; | |
~省略~ | |
@NgModule({ | |
declarations: [ | |
~省略~ | |
], | |
imports: [ | |
AngularFireModule.initializeApp( | |
firebaseConfig, | |
firebaseAuthConfig | |
), | |
], | |
~省略~ | |
// 以下の値は、apiKeyなどの取得で取得した値。 | |
export const firebaseConfig = { | |
apiKey: 'APIキー', | |
authDomain: 'ドメイン', | |
databaseURL: 'URL', | |
storageBucket: 'ストレージバケット' | |
}; | |
// 以下の値は、認証設定。Google認証をリダイレクトで行う。 | |
export const firebaseAuthConfig = { | |
provider: AuthProviders.Google, | |
method: AuthMethods.Redirect | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version='1.0' encoding='utf-8'?> | |
<widget id="ここです。" ...> | |
... | |
</widget> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ionic start --v2 <プロジェクト名> | |
# angular cliの場合 ng new <プロジェクト名> | |
cd <プロジェクト名> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm install angularfire2 firebase --save |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
keytool -exportcert -list -v \ | |
-alias androiddebugkey -keystore ~/.android/debug.keystore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SHA1: 〜〜〜〜ハッシュ値〜〜〜〜 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# npmから取得する場合 | |
cordova plugin add cordova-plugin-googleplus --save --variable REVERSED_CLIENT_ID=ここにiOSの手順で取得したIDを入れる | |
# githubから最新を取得する場合 | |
cordova plugin add https://github.com/EddyVerbruggen/cordova-plugin-googleplus --save --variable REVERSED_CLIENT_ID=ここにiOSの手順で取得したIDを入れる | |
cordova prepare |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
login(){ | |
window['plugins'].googleplus.login( | |
{ | |
// 'scopes': '', | |
'webClientId': 'ここにAndroidの手順で取得したgoogle-services.jsonのclient-idを入れる', | |
'offline': false, | |
}, | |
function (authData) { | |
alert(JSON.stringify(authData)); // do something useful instead of alerting | |
}, | |
function (msg) { | |
alert('error: ' + msg); | |
} | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ionic run android --consolelogs --livereload --device |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ngOnInit(){ | |
window['plugins'].googleplus.login( | |
{ | |
// 'scopes': '', | |
'webClientId': 'ここにAndroidの手順で取得したgoogle-services.jsonのclient-idを入れる', | |
'offline': false, | |
}, | |
function (authData) { | |
let credential = (<any>firebase.auth.GoogleAuthProvider).credential(authData.idToken); | |
firebase.auth().signInWithCredential(credential); | |
}, | |
function (msg){ | |
console.log('acquireAuth error: ' + msg); | |
} | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cordova run android --device |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { AngularFire, | |
FirebaseAuthState} from 'angularfire2'; | |
@Component({ | |
templateUrl: 'テンプレート名.html' | |
}) | |
export class Test{ | |
constructor(private af :AngularFire){} | |
// ログインメソッド。templateのボタンクリックで呼び出される。 | |
login() :firebase.Promise<FirebaseAuthState>{ | |
return this.af.auth.login(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ionic serve | |
# Angularの場合 ng serve |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ionic platform add android |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ionic run android --consolelogs --livereload --device | |
# avdで起動する場合、 --deviceは不要 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"oauth_client": [ | |
{ | |
"client_id": "ここです", | |
"client_type": 3 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<key>REVERSED_CLIENT_ID</key> | |
<string>ここです</string> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- ページにボタンを追加します。前後のコードは省きます。 --> | |
<button ion-button (click)="login()">Login</button> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment